[英]Sum input from JOptionPane
The code I have is pretty clear, all it does so far is prompt the user for 10 inputs of integers, which I am trying to sum. 我拥有的代码非常清楚,到目前为止,它所做的只是提示用户输入10个整数,这是我要求和的。 I want to make it so that after each number is entered, it's added to the sum variable.
我想这样做,以便在输入每个数字之后,将其添加到sum变量中。 How can i do this?
我怎样才能做到这一点?
Here's the code. 这是代码。
int x = 10;
int i = 1;
int maxNumber = 100;
int sum = 0;
while (i <= 10) {
x = Integer.parseInt(JOptionPane.showInputDialog("Enter one grade at a time."));
i++;
}
You can do: 你可以做:
while (i <= 10) {
x = Integer.parseInt(JOptionPane.showInputDialog("Enter one grade at a time."));
i++;
sum+=x; //This line will keep the total
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.