KatsolAgency

Programming languages and web development including java , html, css ,java script,Tutorials Android phone tricks and Tech news around the world.

Monday, July 31, 2017

Nested Switch in java

Program6 - Nested Switch in java


Java Statements Example

This example shows how to use nested switch statements in a
java program.
Like any other Java statements, switch statements can also be nested in each other as given in
below example.


public class NestedSwitchExample {
public static void main(String[] args) {

int i = 0;
int j = 1;
switch(i)
{
case 0:
switch(j)
{
case 0:
System.out.println("i is 0, j is 0");
break;
case 1:
System.out.println("i is 0, j is 1");
break;
12
default:
System.out.println("nested default
case!!");
}
break;
default:
System.out.println("No matching case found!!");
}
}
}

Output would be,
i is 0, j is 1

    Choose :
  • OR
  • To comment
No comments:
Write comments