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.

16th Nov 2016, 9:50 AM
Ali Anando
Ali Anando - avatar
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..
16th Nov 2016, 11:41 AM
Harry Nguon
Harry Nguon - avatar
0
thanks
16th Nov 2016, 12:48 PM
Ali Anando
Ali Anando - avatar