-4

The output should be the salary + rise 4% or 6%. This is my code:

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

But the output is always only the value of y (the salary without the rising) !

Also how I can print that sentence and the variable z in the same line? Like this for example:

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

but that doesn't work.

Nayuki
  • 17,911
  • 6
  • 53
  • 80
saba7o0o
  • 35
  • 1
  • 4

1 Answers1

0

First part: When you write 6/100*y, it's equal to (6/100)*y. But the expression 6/100 is integer division, which is equal to 0. Thus 0*y = 0. What you want to do is change 6/100 to 0.06, and 4/100 to 0.04.

Second part: The correct syntax is System.out.println("YOUr salary is: " + z);.

Nayuki
  • 17,911
  • 6
  • 53
  • 80
  • Without explaining why those changes should be made, this is a comment and not a (good) answer. – Eric J. Jun 03 '15 at 22:50