Java - Nested if statement

Introduction

The if-else statement can be nested, as shown:

Demo

public class Main {
  public static void main(String[] args) {
    int num1 = 20;
    int num2 = 30;
    int num3 = 40;
    if (num1 > 50) {
      if (num2 < 30) {
        num3 = num3 + 130;/*from   ww  w. ja v  a  2s. co m*/
      } else {
        num3 = num3 - 130;
      }
    } else {
      num3 = num3 - 200;
    }
    System.out.println("num2 = " + num2);
    System.out.println("num2 = " + num3);
  }
}

Result

Related Topic