Java If_.Else
Java If_.Else
< /
/ Else >
Presented by
Jarren Louie Garcia
Arvin Lester Diaz
Example
In the example below, we test two values to find out if 20 is greater than 18. If the condition is true, print
some text:
Example
public class Main {
public static void main(String[] args) {
int time = 20;
if (time < 18) {
System.out.println("Good day.“);
} else {
System.out.println( "Good evening.“ );
}
}
}
</Else IfUse else if to specify a new condition to test, if the first
condition is false.
It can be used to replace multiple lines of code with a single line, and is most often used to
replace simple if else statements:
THE END