dimanche 23 août 2020

Need help figuring out if statement evaluation in Java [closed]

Okay so the following code should output "x: 0" because the 'if' statement should evaluate false and not run the block. However running it I got the output "x: 49", I ran this in both eclipse and Dr. Java and got the same result. What am I missing?

    int x = 0;
    int y = 0;
    System.out.print("Please enter y: ");
    Scanner in = new Scanner(System.in);
    y = in.nextInt();
    if (y > 50);
    {
       x = y;
    }
    System.out.println("x: " + x);

Screenshot of unexpected output

Aucun commentaire:

Enregistrer un commentaire