mercredi 3 juin 2015

java code: if statement not the expected output

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.

Aucun commentaire:

Enregistrer un commentaire