问题描述:

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!

for (int i = 0; i < varOptions.size(); ++i) {

System.out.print(varOptions.get(i) + ": ");

double value = myScanner.nextDouble();

}

网友答案:

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.

网友答案:

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

相关阅读:
Top