The if-else-if Ladder

It looks like this:

 
if(condition) 
   statement; 
else if(condition) 
   statement; 
else if(condition) 
   statement; 
. 
.
else 
   statement;

Here is a program that uses an if-else-if ladder.

 
public class Main {
  public static void main(String args[]) {
    int month = 4;
    String value;
    if (month == 1 )
      value = "A";
    else if (month == 2)
      value = "B";
    else if (month == 3)
      value = "C";
    else if (month == 4)
      value = "D";
    else
      value = "Error";

    System.out.println("value = " + value);
  }
}

Here is the output produced by the program:


value = D
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.