How do you create a variable amount of variables?

Viewed 90

I am designing a program in java that processes the function of a graph; the user inputs the degree of x and then a loop runs for the user to input the co-efficients (integers) of all the degrees of x. However, I am struggling with storing this information because I cannot change the variable while the loop is running (if the user is inputing a quadratic function, then 3 variables are required but only 2 varibles are required if it is a linear function) and the variable just gets reassigned values. Is there anyway to change the variable (perhaps if the variable is a, increase the unicode to b the next time the loop runs) or any other method/function that would be useful?

1 Answers

Well, you can have a List<Integer> coefficients = new LinkedList<>() and add all those int to it.

LinkedList is used so that order to which items are added is preserved.

Related