+ 1
Possibilities of loops
I have a for loop and I want to access the individual result like the first number is 10 and the second is 20 and third is 40... Is it possible to access individual result of this loop in my code? If so how? https://code.sololearn.com/cBeFka6Pro3r/?ref=app
4 Respuestas
+ 4
The variable i allows you to access the results.
If you want each result to be stored individually, perhaps use an array.
Example/
int[] array = new int[100];
// fill array with appropriate values
for(int i = 10, index = 0; i < 10000; i*=2)
array[index++] = i;
Now you can do as you please with the array!
+ 3
Sry for the late response, but:
The code I wrote works fine for me. Make sure it is exact and there are no extra words.
Perhaps try writing your own similar thing if it is not working. The idea was just to store all the numbers into an array, that way you can do whatever you want with any of those numbers.
As a random guess, did you happen to forget the comma between: "i = 10" and "index = 0"?
Should be: "int i = 10, index = 0"
+ 1
@Rrestoring faith I'm getting an error with that code you written "illegal character"
0
Thank you for taking your time to answer my question. It working fine now.