Nested if statements

A nested if is an if statement inside another another if statement or else.

public class Main {
  public static void main(String[] argv) {
    int i = 10;
    int j = 4;
    int k = 200;
    int a = 3;
    int b = 5;
    int c = 0;
    int d =0;
    if (i == 10) {
      if (j < 20){
        a = b;
      }
      if (k > 100){
        c = d;
      }
      else{
        a = c;
      }
    } else{
      a = d;
    }
    System.out.println("a = " + a);
    System.out.println("b = " + b);
    System.out.println("c = " + c);
    System.out.println("d = " + d);
    
  }
}

The output:


a = 5
b = 5
c = 0
d = 0
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.