Nested if Statement is one of the decisions making statements in Java that flows according to certain conditions.A nested if statement is an if-else statement with another if statement as the if body or the else body.When there is an if statement within another if statement it is known as a nested if statement.
Syntex :-
If (cond1)
{
// Executes when the cond1 is satisfied If (cond2)
{
// Executes when the cond2 is satisfied
}
}
Q.) W.A.P to print odd or even number ?
//Nested-if Java program with if conditions only
public class NestedIfExample {
public static void main(String args[]) {
//declare 2 variables and store some values in it
int num1 = 23;
int num2 = 45;
//if the number 1 is 23
if( num1 == 23 ) {
//if number is 45
if( num2 == 45 ) {
System.out.print("Number 1 is :"+ num1 +" and Number 2 is :"+ num2);