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); } }

25th Nov 2017, 12:00 PM
d.praveenraj
d.praveenraj - avatar
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
25th Nov 2017, 12:05 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 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]
25th Nov 2017, 12:17 PM
Momo Belia
Momo Belia - avatar
0
thanks for your answers
3rd Dec 2017, 9:24 AM
d.praveenraj
d.praveenraj - avatar