I have a following sample code from my lecture note.
int[] a = new int[3];
a[0] = 1;
for (int i = 1; i < a.length; i++) {
a[i] = a[i-1] + i;
}
And I am assuming that this will return
[1,2,3]
after running the following code.
Because the loop starts from 1 and counts up to 3. when the first loop gets executed i is assinged as 1 and [1-1]+1 and the result is 1 and next i becomes 2 and result is 2.....
I did not think a[0]=1; was doing anything much.
But I am not sure if that is correct.
Could and one tell me if my assumption is correct, please?
Well, not exactly: