+ 1
what is that myArr[0][2]=42
11 Answers
+ 2
assign a new value in mrArr[0][2]=42
+ 1
int [][] my_arr = {{0,1,2},{3,4,5}};
/*{0,1,2} is a row, {3,4,5} is another row so imagen it like this :
{0,1,2} first row its row number 0 .
{3,4,5} the second row its row number 1 .
rows are written in the first square brackets .
..............
columns are written in the second square bracket .*/
int x = myarr [1][0];
/* [1] is the row {3,4,5}
[0] means the number 3 (the first number in row 1 )
so its called column .*/
system.out.println(x);
+ 1
thanks :)
+ 1
That 42 is you are assigning to the array element in 0th row 2nd column. But actually we have 3 in the program. That 3 is replaced by 42 when you want to see the element in myArr[0][2]
0
what is that 42?
0
output in my code will be //3
0
that 42 is from a code its like mine but dfrnt Num. !
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);
}
}
can u explain in this scenario..what is that 42?
0
welcome
0
@Ahamad shah so your x = 4
0
No one is really answering the question which is what is that "42" doing there!?