Java if statement Question 2

Question

What is the output of the following code?

public class Main {
  public static void main(String[] args) {
    int x = 3, y = 2, z = 100;

    if (x > 2) {
      if (y > 2) {
        z = x + y;/*from  w w w.jav  a  2 s . com*/
        System.out.println("z is " + z);
      }
    } else
      System.out.println("x is " + x);
    
    
    x = 3;
    y = 4;
      
    if (x > 2) {
      if (y > 2) {
        z = x + y;
        System.out.println("z is " + z);
      }
    } else
      System.out.println("x is " + x);
    
    x = 2;
    y = 2;
      
    if (x > 2) {
      if (y > 2) {
        z = x + y;
        System.out.println("z is " + z);
      }
    } else
      System.out.println("x is " + x);
    
  }
}


z is 7
x is 2



PreviousNext

Related