Advertisement
steverobinson

Nested Switch|Example

Jun 23rd, 2011
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. /*program to implement nested switch case
  2. Input   Output
  3. 0   0     0
  4. 0   1     1
  5. 1   0     2
  6. 1   1     3
  7. */
  8.  
  9. /*
  10. Example:
  11.  
  12. Enter boolean value with space.....
  13. 1 1
  14. Value is 3
  15. */
  16.  
  17.  
  18. import java.util.Scanner;
  19. class MainClass{
  20.  
  21.     public static void main(String arg[])
  22.     {
  23.         int a,b;
  24.         Scanner input=new Scanner(System.in);
  25.        
  26.         System.out.println("\nEnter boolean value with space.....");
  27.         a=input.nextInt();
  28.         b=input.nextInt();
  29.        
  30.         switch(a)
  31.         {
  32.             case 0:
  33.                 switch(b)
  34.                 {
  35.                     case 0:
  36.                         System.out.println("Value is 0");
  37.                         break;
  38.                     case 1:
  39.                         System.out.println("Value is 1");
  40.                         break;
  41.                 }
  42.                 break;
  43.             case 1:
  44.                 switch(b)
  45.                 {
  46.                     case 0:
  47.                         System.out.println("Value is 2");
  48.                         break;
  49.                     case 1:
  50.                         System.out.println("Value is 3");
  51.                         break;
  52.                 }      
  53.                 break;
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement