0
How to store outputs of a for loop in an array.
for example i use a for loop and get 1 2 3 4 5 now how can i store all those outputs in an array.
2 ответов
+ 1
create the array before the for loop e.g.
int[] output = new int[size]; (size is 5 in this case)
and inside your for loop
output[i] = outputVariable; (whatever the output is)
("i" is whatever you used as the increment variable in the for loop)
So you are pretty much adding each individual outcome to the new array as you are iterating through whatever you are doing in the for loop.
You can also manually allocate each outcome to the new array's indexes e.g.
output[0] = 1;
output[1] = 2; etc..
0
thanks