+ 2
I expected 3 answer of this question š³.... what's wrong ????
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.
+ 3
Ipang oh thanks Man šāļø
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);
}
}
- 1
I was expecting 3 as well