I initialize the salary and this is the result i get, is it correct, to me it doesnt look correct, I could be wrong

public static void main(String[] args) {
        Scanner scan = new Scanner (System.in);
        int age,  sum, difference, old_salary, new_salary, salary = 0;

        System.out.println("Please enter the person age");
        age = scan.nextInt();

        System.out.println("Please enter the person old salary");
        old_salary = scan.nextInt();

        System.out.println("Please enter the person new salary");
        new_salary = scan.nextInt();

        if(age > 32)

           sum = old_salary + 1000;

           System.out.println("your salary is " + salary );


        else if (age<=32)

            old_salary = new_salary - 500;
            difference = old_salary - 500;

            System.out.println("your new salary is "  + salary);
            System.out.println("your age is " + age);

this is the result I get when I run the program. when I test it with the age 29 which is less than 32 and when i test it with 33 which is greater than 32, i used random salary range. checking to see if it run and this is the result. i could be wrong but is this the correct answer

Please enter the person age
Please enter the person old salary
Please enter the person new salary
your new salary is 0
your age is 29
BUILD SUCCESSFUL (total time: 9 seconds)

3 Years
Discussion Span
Last Post by divinity02

the reason why you get 0 is exactly the same as I explained in your other thread.

System.out.println("your salary is " + salary );

this should be replaced with:

System.out.println("your salary is " + sum );


System.out.println("your new salary is " + salary);

should be replaced with

System.out.println("your new salary is " + old_salary);

your entire code is a mess. you are using variables you shouldn't use, and you are not always updating the variables you should be using.

the above is just to get a more correct value, but it still wouldn't be completely correct (I guess)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.