我无法理解并且可能无法记住您如何不断添加到字段/变量。我希望它记住我最后的输入并将其添加到 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);
}
}
最佳答案
也许a.setI(a.getI() + scan.nextInt())
关于java - 如何在java中不断添加你的值(int)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54467886/