Java 如何从一种方法到另一种方法获取变量?如何从void add()中获取int x?

Java 如何从一种方法到另一种方法获取变量?如何从void add()中获取int x?,java,Java,我想把x和y的值传递给add()方法 公共类算术{ public static void assuming(){ System.out.println("Please insert the first number"); Scanner read = new Scanner(System.in); int x = read.nextInt(); System.out.println("Please insert the second number"); Scanner read1 = ne

我想把x和y的值传递给add()方法 公共类算术{

public static void assuming(){ 

System.out.println("Please insert the first number");
Scanner read = new Scanner(System.in);
int x = read.nextInt();

System.out.println("Please insert the second number");
Scanner read1 = new Scanner(System.in);
int y = read1.nextInt();
}


void add()
{
// How to get values of int x and int y from upper method in here ?
}

在假设方法中创建methdd调用
add(x,y);

int answer = add(x,y);
然后修改
add
函数

int add(int x,int y)
{
   return x+y;
}

由于x,y是基元类型,您可以在调用时通过value
void add(int x,int y)
传递。创建一个函数调用
add(x,y);
问题(标题)一点也不清楚,尽管代码显示了一些基本问题,例如从静态方法调用实例方法等等……我对编程是新手