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); } } | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

What is the use of myArr[0][2]=42; without this line the outcome will be the same

14th Oct 2016, 11:03 AM
Gopal Varma Gottimukhala
Gopal Varma Gottimukhala - avatar
7 Answers
+ 2
acces you array is made like this [upper_number][lower_number] __0__ _1_ __2__ { {1, 2, 3}, {4}, {5, 6, 7} }; _0_1_2_ _0_ _0_1_2_ myArr[0][2] = 42; - in here you modify the value from [0][2] so instead of 3 will be 42. new array will be { {1, 2, 42}, {4}, {5, 6, 7} } then, int x = myArr[1][0]; System.out.println(x); you get the value from [1][0], and print it, so that will be 4
14th Oct 2016, 3:00 PM
Andrei Dragu
Andrei Dragu - avatar
+ 1
That's entirely true. Maybe it was just there as an example of how to modify a value from myArr?
14th Oct 2016, 11:13 AM
Zen
Zen - avatar
+ 1
your object array "myArr [0][2] = 42" is being deleted by the garbage collector because you are creating two objects that use the same allocated space rendering the "2nd object" pointless.
15th Oct 2016, 1:58 AM
Eric Kershner
Eric Kershner - avatar
0
its only modify the value..
14th Oct 2016, 11:13 AM
Anime MADhouse
Anime MADhouse - avatar
0
please help me to build a database application with java and i am new to java
15th Oct 2016, 10:33 AM
Phumlani Blessing Shezi
Phumlani Blessing Shezi - avatar
- 1
4
14th Oct 2016, 11:11 AM
Anime MADhouse
Anime MADhouse - avatar
- 1
the answer would be 4
14th Oct 2016, 2:39 PM
Sandesh Uttarwar
Sandesh Uttarwar - avatar