
if가 true일 때, if { then절 } then절을 수행하고
if가 false일 때, if { then절 } 밖 else{ then절 } 의 then절을 수행한다.

if가 true일 때, if { then절 } then절을 수행하고,
if가 false일 때, else if { then절 } 의 then절을 수행한다.
else if가 true일 때, else if { then절 } then절을 수행하고,
else if가 false일 때, else { then절 } then절을 수행한다.
아래의 예제의 출력값은 ‘2’다.
package org.opentutorials.javatutorials.condition;
public class ElseDemo {
public static void main(String[] args) {
if (false) {
System.out.println(1);
} else if (true) {
System.out.println(2);
} else if (true) {
System.out.println(3);
} else {
System.out.println(4);
}
}
}