11:15 pm - Sunday July 15, 2018

Java program for Nested Switch Case Statements

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/**

*@author :CandidJava.com

*@descriptions : This program explain how to using the Nested Switch case statement

*/

class NestedSwitch {

public static void main(String[] args) {

int i = 0; //create and assign the variable for i

int j = 1; // create and assign the variable for j

//create the switch statement for the variable i

switch(i) {

case 0:

// create the nested switch statement for the variable j inside the switch statement for i

switch(j) {

case 0:

System.out.println("i is 0, j is 0");

break; // it is true means it displays the output and exit

case 1:

System.out.println("i is 0, j is 1");

break;  // it is true means it displays the output and exit

//if the above statements are not true then default is execute

default:

System.out.println("nested default case!!");

}

break; // it is for switch statement I

//it displays the default output if the above statements are false

default:

System.out.println("No matching case found!!");

}

}

}

Output:

D:\ CandidJava\code>javac NestedSwitch.java

D:\ CandidJava\code>java NestedSwitch

i is 0, j is 1

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply