【发布时间】:2017-04-26 10:13:10
【问题描述】:
class Method {
public static void main(String[] args) {
int a =1, b=2;
method1(a,b);
method2();
}
public static int method1(int a, int b) {
int c = (a + b);
return c;
}
public static void method2() {
int z=11;
if (z >= method1(a,b)) {System.out.println("Method 2 works");}
}
}
-在 if 语句中获取enter image description hereerror
【问题讨论】:
-
在 method2() 中,您尝试使用参数 a、b,但它们不在该方法中。
-
a和b是方法参数,而不是结果。它们在method2中未定义。你想在method2中总结什么?z应该大于什么? -
您必须将 a 和 b 参数传递给 method2 才能被方法 1 使用