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.

13th Dec 2022, 5:28 AM
Mustakim Rahman
Mustakim Rahman - avatar
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.
13th Dec 2022, 7:35 AM
Lothar
Lothar - avatar
+ 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.
13th Dec 2022, 5:42 AM
Ipang
+ 4
Mustakim Rahman Simple a is already 2 So rangeArray[4] = 2 + 4 = 6;
13th Dec 2022, 6:40 AM
A͢J
A͢J - avatar