Use if/else in a nested fashion, refining conditions to more specific, or narrower, tests at each point. : if « Statements « SCJP






public class MainClass {
  public static void main(String[] argv) {
    int hours = 3;
    if (hours > 1) {
      System.out.println("evening");
    } else if (hours > 2) {
      System.out.println("afternoon");
    } else {
      System.out.println("morning");
    }
  }
}
evening








5.7.if
5.7.1.The basic format of an if statement
5.7.2.The expression in an if statement must be a boolean expression.
5.7.3.Use an else block to execute code that is executed under the conditions that the test returns false.
5.7.4.Use if/else in a nested fashion, refining conditions to more specific, or narrower, tests at each point.