如何在java中不断添加值(int)?
我很难理解,也可能记不起您是如何不断添加到字段/变量的。我希望它记住我最后的输入,并将其添加到int值的总和中。所以每次我输入一个新的数字,总数就会不断增加 我还有另外两个类,只包含Getter/Setter和Construtor如何在java中不断添加值(int)?,java,variables,int,Java,Variables,Int,我很难理解,也可能记不起您是如何不断添加到字段/变量的。我希望它记住我最后的输入,并将其添加到int值的总和中。所以每次我输入一个新的数字,总数就会不断增加 我还有另外两个类,只包含Getter/Setter和Construtor public class foo { static Scanner scan = new Scanner(System.in); private static int input; static A a = new A(10); sta
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())
不要在(1!=2)时使用像这样的空洞语句。改用while(true)
。