0
why this "myArr[0][2]=42;" is used in this program
public class Program { public static void main(String[] args) { int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; myArr[0][2] = 42; int x = myArr[1][0]; System.out.println(x); } }
3 Answers
+ 8
They have just assigned a new value to myArr[0][2] in order to show how to assign a value in a specific position. So now the values of first row are 1,2,42 instead of 1,2,3
+ 1
you replaced myArr[0][2] with 42, that mean 1,2,3 will be 1,2,42
the output is 4, since you declare x as myArr[1][0]
0
thanks for your answers