我的程序需要帮助。我需要在two()中使用变量“ three”,“ four”,但是我不知道如何。请帮忙。
public class Main {
public static void main(String[] args) {
one()
}
public static void one(){
Integer three;
Integer four;
Integer five;
three = 3;
four = 4;
two();
}
public static void two(){
five = three + four;
System.out.println(five);
}
}
使它们成为类变量,因此将它们带出您的方法之外:
static Integer three;
static Integer four;
static Integer five;
public static void one(){
three = 3;
four = 4;
two();
}
并更改one()
为one();
或者,您可以为它们的two()
方法设置参数:
public static void one(){
Integer three;
Integer four;
three = 3;
four = 4;
two(three, four); // add parameters here
}
public static void two(Integer three, Integer four){
Integer five; // declare five here
five = three + four;
System.out.println(five);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句