+ 2

I expected 3 answer of this question šŸ˜³.... what's wrong ????

https://code.sololearn.com/cBzxoAkqqx3x/?ref=app

7th Mar 2022, 2:27 AM
Davinder Kumar
Davinder Kumar - avatar
4 Answers
+ 4
int [] arr = { 1, 2, 3, 4 }; int x = arr[ 2 ]; // 3 System.out.println( arr[ x ] ); // arr[ 3 ] = 4 You used <x> as index, but <x> was assigned arr[ 2 ] whose value were 3.
7th Mar 2022, 2:32 AM
Ipang
+ 3
Ipang oh thanks Man šŸ˜žāœŒļø
7th Mar 2022, 2:35 AM
Davinder Kumar
Davinder Kumar - avatar
0
public class Program { public static void main(String[] args) { int [] arr={1,2,3,4}; int x=arr[2]; // your should assign x not arr[x] // because x = 3 //whereas arr[x] = arr[3] = 4 System.out.println(x); } }
9th Mar 2022, 2:41 AM
Legends Developer
- 1
I was expecting 3 as well
7th Mar 2022, 2:30 AM
Alusine T. Lavalie
Alusine T. Lavalie - avatar