Java if else ladder statement
In this chapter you will learn:
- What is Java if else ladder statement
- Syntax for Java if else ladder statement
- Example - Java if else ladder statement
Description
The if else ladder statement is used to work on multiple conditions.
Syntax
The if-else-if Ladder looks like this:
if(condition) /* ww w . jav a2s. co m*/
statement;
else if(condition)
statement;
else if(condition)
statement;
.
.
else
statement;
Example
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;/*from w ww .jav a 2s . c o m*/
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:
Next chapter...
What you will learn in the next chapter: