+ 1

Why the answer to this questions is 2?

int[] arr ={1,2,3,4}; int x= arr[arr[ ]]; System.out.print(x);

5th Nov 2019, 3:20 PM
Miosotis
9 Answers
+ 12
As we know array index starts from 0 so here it will start from 0 Int x = arr[arr[]] = arr[arr[0]]; value at location arr[0] is 1 so now Int x= arr[arr[]] = arr[1]; Now value at location arr[1] is 2 Which is your output
7th Nov 2019, 1:57 PM
Ayushi Gujarati
Ayushi Gujarati - avatar
+ 1
Is the square bracket empty?
5th Nov 2019, 3:29 PM
Avinesh
Avinesh - avatar
+ 1
It's not even running, their is probably a 0 inside the bracket.
5th Nov 2019, 3:55 PM
Avinesh
Avinesh - avatar
+ 1
Then bracket should contain 2 inside.
5th Nov 2019, 4:06 PM
Avinesh
Avinesh - avatar
0
Yes
5th Nov 2019, 3:30 PM
Miosotis
0
The empty space of the bracket must be filled.
5th Nov 2019, 3:39 PM
Miosotis
0
Yes, where did you find that question from?
5th Nov 2019, 3:48 PM
Avinesh
Avinesh - avatar
0
In a Sololearn challenge.
5th Nov 2019, 3:50 PM
Miosotis
0
Te original question is: Fill in the blank to output 4.
5th Nov 2019, 4:03 PM
Miosotis