ICSE 10th Standard Notes – Nested If Statement in java – ICSE Nested If Statement with example

ICSE 10th Standard Notes – Nested If Statement in java – ICSE Nested If Statement with example

A nested If is an If that has another if in its body or in the body of the else block or in both.

Syntax :-

if(expression)

{

True Block of Statements

if(expression)

{

__________

__________

}

else

{

__________

__________

}

}

else

{

False Block of Statements

if(expression)

{

__________

__________

}

else

{

__________

__________

}

}

Statements Outside If Block

Examples :-

Java Program to given Character is a Digit, Letter or a Special Character If-Else Statements.

 

import java.io.*;

class Check1

{

public static void main(String args[])throws IOException

{

DataInputStream dis = new DataInputStream(System.in);

char ch ;

System.out.print(” Enter a character : “);

ch = (char) dis.read();

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

{

System.out.println(” Character is an Alphabet “);

if(ch==’a'||ch==’A'||ch==’e'||ch==’E'||ch==’i'||ch==’I'|| ch==’o'||ch==’O'||ch==’u'||ch==’U')

System.out.println(“Alphabet:” + ch + ” is a Vowel “);

else

System.out.println(” Alphabet:”+ch+”is a Consonant “);

}

else

{

if(ch>=’0′ && ch<=’9′)

System.out.println(ch + ” Character is a Digit “);

else

System.out.println(ch+” is a Special Character “);

}

}

}

Leave a Reply

Your email address will not be published. Required fields are marked *

Security Code: