我想将 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 ?
}
add(x,y);
在假设方法中创建一个方法调用。
int answer = add(x,y);
之后修改你的add
功能
int add(int x,int y)
{
return x+y;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句