Nested if statement in Java

When a complete if or if-else statement is written within another if statement, it is known as nesting of the if statement. The nested block can be within the if block or inside the else block.

 

Example...

class NestedIf

{

public static void main(String aa[])

{

char ch='&';

if((ch<='0' && ch>='9')||(ch<='z' && ch>='a')||(ch<='Z' && ch>='A'))

{

if((ch<='z' && ch>='a')||(ch<='Z' && ch>='A'))

{

if(ch<='Z' && ch>='A')

System.out.println(ch+"is uppercase alphabet");

else

System.out.println(ch+"is lowercase alphabet");

}

else

{

System.out.println(ch+"is numeric character");

}

}

else

{

System.out.println(ch+"is neither a number not a alphabet");

}

}

}

Nested If statement in Java

Explanation…

In this program input a character(char ch='&'; any character) from the keyboard then checks if it is alphanumeric. If yes then check if it is an alphabet, if yes check for uppercase or lower case alphabet.