I have an array of elements and I want to use the elements in the array as variables.
I want to do this because I have an equation, the equation requires multiple variable inputs, and I want to initialize an array, iterate through it, and request input for each variable (or each element of the array).
So I have an array like this:
String variableArray[] = {"a", "b", "c"}
And now I'm iterating through this array and getting the input from the user:
for(int i=0; i<3; i++) {
System.out.printf("Enter value for %s: ", variableArray[i]);
int variableArray[i] = keysIn.nextInt();
}
The problem is this line doesn't compile:
int variableArray[i] = keysIn.nextInt();
In essence, I want to use the elements of the array variableArray[] (i.e. a, b, and c) as variables so I don't have to do the same process for each variable. I can't imagine how it's done when there are many variables to input (I wouldn't want to type that all out).
tl;dr I want to streamline the process of inputting values for multiple variables.
intfrom the declaration of the "variable":variableArray[i] = keysIn.nextInt();