【发布时间】:2019-06-25 08:17:06
【问题描述】:
我无法理解并且可能无法记住您是如何不断添加到字段/变量中的。我希望它记住我的最后输入并将其添加到 int 值的总和中。所以每次我输入一个新数字时,总数都会增加。
我还有另外 2 个只包含 Getter/Setter 和一个构造函数的类
public class foo {
static Scanner scan = new Scanner(System.in);
private static int input;
static A a = new A(10);
static B b = new B(10);
public static void main(String[] args) {
while (1 != 2) {
keepValue();
}
}
public static void keepValue() {
a.setI(scan.nextInt());
int sum = a.getI() + b.getJ();
System.out.println("the sum of the two numbers is: "+sum);
}
}
【问题讨论】:
-
不要使用像
while(1 != 2)这样的空洞语句。请改用while(true)。