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
29
Please enter the person old salary
3000
Please enter the person new salary
4000
your new salary is 0
your age is 29
BUILD SUCCESSFUL (total time: 9 seconds)

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 );

and

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)

hey thank u a lot stultuske, it work right this time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.