0
Need solution
int a=2; int[] rangeArray = new int [10] for(int i=0; i<10; i++){ rangeArray[i]=a+i;} System.out.println(rangeArray[4]); How the output is 6? Explain please.
3 Respostas
+ 7
Mustakim Rahman ,
in this case just posting your code may not be sufficient. it is extremely helpful to also create and share a suitable task description.
+ 4
When <i> = 0
rangeArray[ 0 ] = 2 + 0
When <i> = 1
rangeArray[ 1 ] = 2 + 1
When <i> = 2
rangeArray[ 2 ] = 2 + 2
When <i> = 3
rangeArray[ 3 ] = 2 + 3
And when <i> = 4
rangeArray[ 4 ] = 2 + 4
And so on, until <i> equals 10, where loop ceased repetition.
+ 4
Mustakim Rahman
Simple a is already 2
So rangeArray[4] = 2 + 4 = 6;