1else if statement is used to specify new condition if first condition is false.
2Syntax:
3
4if(condition1)
5{
6 // execute if condition1 is true
7}
8else if (condition2)
9{
10 // execute if condition2 is true
11}
12else if (condition3)
13{
14 // execute if condition3 is true
15}
16else
17{
18 // execute if conditions 1, 2 and 3 becomes false
19}
1import java.io.*;
2public class JavaIfElse
3{
4 public static void main(String[] args)
5 {
6 int number = 15;
7 // check if number is divisible by 2
8 if(number%2 == 0)
9 {
10 System.out.println(number + " is even number");
11 }
12 else
13 {
14 System.out.println(number + " is odd number");
15 }
16 }
17}
1int x = 3;
2
3if (x == 3) {
4 // block of code to be executed if the condition is true
5} else {
6 // block of code to be executed if the condition is false
7}
1int x = 3;
2
3if (x == 3) {
4 // block of code to be executed if the condition is true
5}