Question: 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.

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.

Here is the skeletal structure of the 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(){

}

```

}

Answer: 
You should place the variable outside of all methods but within the class, creating global access.

```
public class ClassName
{
    public int x;
    public int y;

    public void method1()
    {
        x = 3;
    }

    public void method2()
    {
        y = 1;
    } 
}

```
Move the variable at class level, make it a field in the class.

Since you're learning, it will be better to not use `static` fields nor methods except for the `main` method.