Ok so I need the variable "value" to have a different name every time the cycle repeats. I am fairly new to java so I am unsure how to go about this. Thanks for the help in advance!
好的,所以每次循环重复时我都需要变量“value”来获得不同的名称。我对java很新,所以我不确定如何解决这个问题。我在这里先向您的帮助表示感谢!
for (int i = 0; i < varOptions.size(); ++i) {
System.out.print(varOptions.get(i) + ": ");
double value = myScanner.nextDouble();
}
2 个解决方案
#1
1
You can't do that. Maybe you can use value
as an array?
你不能这样做。也许你可以使用值作为数组?
double[] value = new double[varOptions.size()];
for (int i = 0; i < varOptions.size(); ++i) {
System.out.print(varOptions.get(i) + ": ");
value[i] = myScanner.nextDouble();
}
In array value
you will have an array with all input values.
在数组值中,您将拥有一个包含所有输入值的数组。
#2
0
This is a good place to use an array to store the data:
这是使用数组存储数据的好地方:
double[] someValue = new double[varOptions.size()];
for (int i = 0; i < varOptions.size(); ++i) {
System.out.print(varOptions.get(i) + ": ");
someValue[i] = myScanner.nextDouble();
}
After the for loop, someValue, an array of double values, contains all answers
在for循环之后,someValue(一个double值数组)包含所有答案
#1
1
You can't do that. Maybe you can use value
as an array?
你不能这样做。也许你可以使用值作为数组?
double[] value = new double[varOptions.size()];
for (int i = 0; i < varOptions.size(); ++i) {
System.out.print(varOptions.get(i) + ": ");
value[i] = myScanner.nextDouble();
}
In array value
you will have an array with all input values.
在数组值中,您将拥有一个包含所有输入值的数组。
#2
0
This is a good place to use an array to store the data:
这是使用数组存储数据的好地方:
double[] someValue = new double[varOptions.size()];
for (int i = 0; i < varOptions.size(); ++i) {
System.out.print(varOptions.get(i) + ": ");
someValue[i] = myScanner.nextDouble();
}
After the for loop, someValue, an array of double values, contains all answers
在for循环之后,someValue(一个double值数组)包含所有答案