title: Make a variable accessible by all methods
body: <p>I'm a bit new to java and i recently learned about methods(so cool!). I want to know if its possible to declare a variable in my main method and use it in my other methods.</p>
  
  <p>What i am trying to do is create a calculator using methods(just for practice with this new concept) but i dont want to declare the variable every time in each method.</p>
  
  <p>Here is the skeletal structure of the code:</p>
  
  <pre><code>class GS1{
  
  
  
  public static void main (String[]args){
      Scanner input = new Scanner(System.in);
      System.out.println("Enter the math operation to be completed: ");
      String opt = input.nextLine();
      int x,y;  // I tried declaring variables here
      switch(opt){
  
      case  "addition" :
      // addition method goes here
      break;
      case "subtraction":
      //subtraction method goes here
      break;
      case "multiplication":
      //multiplication method   goes  here
      break;
      case "division":
      //division method goes here
      break;
      }
  
  }
  
  static void addition(){
      System.out.println("Enter first value for addition");
      x=input.nextint(); // i get error stating both "x" and "input" cannot be resolved as a variable
  
  
  }
  
  static void subtration(){
  
  
  }
  
  static void Multiplication(){
  
  }
  
  static void Division(){
  
  
  
  }
  </code></pre>
  
  <p>}</p>