title: Nested switch with different expression types
body: <p>I am trying to use the nested switch statement. Is it possible to use different expression types in nested switch statements?</p>
  
  <p>I get the following compiler error:  <code>arith cannot be resolved as variable</code>. </p>
  
  <p>There's a comment to indicate where the error occurs.</p>
  
  <p>Here is my code for your reference:</p>
  
  <pre><code>import java.util.Arrays;
  import java.util.Scanner;
  
  
  class Choice1 {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          // TODO Auto-generated method stub
                  @SuppressWarnings("resource")
  
                  Scanner S = new Scanner(System.in);
  
                  int Source = 0, Target = 0,codePos = 0;
  
                  System.out.println("Enter the Source(1-2) :");
                  Source = S.nextInt();
  
                  System.out.println("Enter the Target Value (1 - 3) :");
                  Target = S.nextInt();
  
  
                  if (Source == 1)
                  {
                      String[] arith = {"Add","Sub"};
                      codePos = Arrays.binarySearch(arith, 0, arith.length, Target);
                  }
                  else if (Source == 2)
                  {
                      String[] Multi = {"Multiplication","Division","Modulas"};
                      codePos = Arrays.binarySearch(Multi, 0, Multi.length, Target);
                  }
                  else
                  {
                      System.out.println("Invalid Value");
                  }
  
                  switch (Source) {
                  case 1:
                      switch (arith[codePos]) {  // &lt;============= !! ERROR HERE !! 
                      case "Add":
                          System.out.println("Addition....!!!");
                          int a,b,c;
  
                          System.out.println("Enter value for A :");
                          a = S.nextInt();
                          System.out.println("Enter value for B :");
                          b = S.nextInt();
  
                          c = a + b;
  
                          System.out.println("The Result " + c);
  
                          break;
                      case "Sub":
                          System.out.println("Subtraction....!!!");
                          int d,e,f;
  
                          System.out.println("Enter value for D :");
                          d = S.nextInt();
                          System.out.println("Enter value for E :");
                          e = S.nextInt();
  
                          f = d - e;
  
                          System.out.println("The Result" + f);
  
                          break;
                      default:
                          System.out.println("Invalid Value...!!!");
  
                      }
                      break;
  
                  case 2:
                      switch (Target) {
                      case 1:
                          System.out.println("multiplication....!!!");
                          int a,b,c;
  
                          System.out.println("Enter value for A :");
                          a = S.nextInt();
                          System.out.println("Enter value for B :");
                          b = S.nextInt();
  
                          c = a * b;
  
                          System.out.println("The Result" + c);
  
                          break;
                      case 2:
                          System.out.println("Division....!!!");
                          int d,e,f;
  
                          System.out.println("Enter value for D :");
                          d = S.nextInt();
                          System.out.println("Enter value for E :");
                          e = S.nextInt();
  
                          f = d / e;
  
                          System.out.println("The Result" + f);
  
                          break;
  
                      case 3:
                          System.out.println("Modulas....!!!");
                          int g,h,i;
  
                          System.out.println("Enter value for G :");
                          g = S.nextInt();
                          System.out.println("Enter value for H :");
                          h = S.nextInt();
  
                          i = g % h;
  
                          System.out.println("The Result" + i);
  
                          break;
                      default:
                          System.out.println("Invalid Value...!!!");
  
                      }
                      break;
                  }
  
              }
          }
  
      }
  
  }
  </code></pre>