Home > Back-end >  Why is this code not working? There is no Output
Why is this code not working? There is no Output

Time:10-31

 public class Main
 {
  public static void main(String[] args) {

    int x=8, y=0, z=1; //random integers
    
  if (x > 0 && y < 0)
  
 {
  if (x==8)
   System.out.print("Yes");
  else if (z > 0)
  System.out.print("No");
 }
 
    }
}

why does this code does not print an output ?

it should print " yes " or " no " because the first if is wrong ?

CodePudding user response:

if (x > 0 && y < 0)

Your y value is 0, so the test y < 0 return false, you do not enter in your first if.

CodePudding user response:

you should change this line

if (x > 0 && y < 0)

to this

if (x > 0 && y <= 0)
  •  Tags:  
  • java
  • Related