java code: if statement not the expected output -


this question has answer here:

the output should salary + rise 4% or 6%. code:

int x = input.nextint();    //x 1,2 or3// system.out.println("enter sallary:"); int y = input.nextint();    // salary// if (x == 1) {     double z = 6/100*y + y;     system.out.print("excellent ur sallary :");     system.out.print(z); } else {     double z = 4/100*y + y;     system.out.print("good ur sallary :");     system.out.print(z);  } 

but output value of y (the salary without rising) !

also how can print sentence , variable z in same line? example:

system.out.print("good ur sallary :", z); 

but doesn't work.

first part: when write 6/100*y, it's equal (6/100)*y. expression 6/100 integer division, equal 0. 0*y = 0. want change 6/100 0.06, , 4/100 0.04.

second part: correct syntax system.out.println("your salary is: " + z);.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -