title: Java calculator using switch case
body: <p>My requirement - <code>calc</code> method should take two numbers from <code>main</code>, and <code>calc</code> will perform all the operations. Everything goes fine until a problem occurs in <code>switch</code> command. I get the error "choice cannot be resolved to a variable".</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Learn {
  
      public static void main(String args[]) {
          int firstnumber, secondnumber, choice;
  
          System.out.println("1- Add");
          System.out.println("2- Sub");
          System.out.println("3- Div");
          System.out.println("4- Mul");
          System.out.print("Enter your choice -");
          Scanner var = new Scanner(System.in);
  
          choice = var.nextInt();
          System.out.print("Enter first number -");
          firstnumber = var.nextInt();
          System.out.print("Enter second number -");
          secondnumber = var.nextInt();
          calc(firstnumber, secondnumber);
      }
  
      public static void calc(int x, int y) {
          int c;
  
          switch (choice) {
              case 1:
                  c = x + y;
                  System.out.print("Output-" + c);
                  break;
  
              case 2:
                  c = x - y;
                  System.out.print("Output-" + c);
                  break;
  
              case 3:
                  c = x / y;
                  System.out.print("Output-" + c);
                  break;
  
              case 4:
                  c = x * y;
                  System.out.print("Output-" + c);
                  break;
          }
      }
  }
  </code></pre>
  
  <p>What am I missing, and how can I fix this?</p>