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
7 Respuestas
+ 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
+ 1
That's entirely true. Maybe it was just there as an example of how to modify a value from myArr?
+ 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.
0
its only modify the value..
0
please help me to build a database application with java and i am new to java
- 1
4
- 1
the answer would be 4