我想将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 ?
}
答案 0 :(得分:1)
在假设方法中创建一个methdd调用add(x,y);
。
int answer = add(x,y);
之后修改您的add
功能
int add(int x,int y)
{
return x+y;
}