I need to write a program that has user input for how many numbers will be inputted, and then inputs them all. I am having trouble figuring out how to declare new variables within a while loop.
How many numbers will you enter? 5
And then, within a while loop, I need to somehow declare five or however many separate variables, but I'm unsure how to do this.
You can use an array or a collection to store a set of values. Collections are more flexible because they can grow and shrink as needed, whereas an array has a fixed size. In your case, if the user specifies that there are five elements, and you can do something like String values = new String[k]; (where k holds the user-specified number of elements). You'd assign values to the array using a statement like: values[i] = someUserSuppliedValue;. To store a bunch of strings in a collection you would do something like List<String> values = new ArrayList<String>();, then assign values to it using a statement like values.add(someUserSuppliedValue);