Published on July 25, 2017
Java tutorial for beginners playlist
Java if else statement
In this video we will discuss “if else” control flow statement in Java with examples.
if else syntax
if (condition) {
statement1a; // if condition is evaluated true
statement2a;
:
}
else {
statement1b; // if condition is evaluated false
statement2b;
:
}
Please note that opening and closing braces are optional when there is single statement. Else is also optional.
Nested if syntax
if (expression-1)
if (expression-2)
statement-1 ;
else
statement-2 ;
else
if (expression-3)
statement-3 ;
else
statement-4;
Nested if example
if (score ]200) {
if (score [400) {
if (score ]300) {
System.out.println(1);
}
else {
System.out.println(2);
}
else {
System.out.println(3);
}
}