Java Control Statements
- Java if Statement
- Java Nested if Statement
- Java if-else-if Statement
- Java Switch Case
- Java Switch with String
- Java Nested Switch
- Java Simple for Loop
- Java for each Loop
- Java Nested for Loops
- Java while loop
- Java continue Statement with for Loop
- Java continue in do-while Loop
- Java break to Exit a for Loop
- Java break with Nested Loops
Java Nested if Statement Example demonstrates how to use nested if statement with an example in Java.
Java Nested if Statement
When there is an if statement inside another if statement then it is called the nested if statement.
Syntax
if(condition_1) {
Statement1(s);
if(condition_2) {
Statement2(s);
}
}
Java Nested if Statement example
package net.javaguides.corejava.controlstatements.ifelse;
public class NetstedIfStatementExample {
public static void main(String[] args) {
int num = 50;
if (num < 100) {
System.out.println("number is less than 100");
if (num == 50) {
System.out.println("number equal to 50");
if (num > 40) {
System.out.println("number is greater than 40");
}
}
}
}
}
Output:
number is less than 100
number equal to 50
number is greater than 40
Comments
Post a Comment