我正在尝试从另一个方法中调用一个方法。我很简单地理解了这一点,直到其中一种方法需要传递一个变量,然后我尝试的任何方法都无法正常工作。
我知道我可以用一种方法来做到这一点,但是我的课程需要我以这种方式进行布局。为什么这行不通?
public class test2 {
public static void testMethod() {
int randomNumber = 1;
}
public static void anotherTestMethod(int randomNumber) {
System.out.println(randomNumber);
}
public static void main(String[] args) {
anotherTestMethod();
}
}