+ 2

I didn't understand

why myArr[0][2] =42 ?

30th Aug 2017, 7:32 PM
kais hasan
kais hasan - avatar
14 Antworten
+ 2
@kais hassn nobody can help you without source.
30th Aug 2017, 7:51 PM
Cain Eviatar
Cain Eviatar - avatar
+ 2
you can see the multi dimensional array defined as MyArr={ {1,2,3}, {4}, {5,6,7} } as [1] [2] [3] [4] [5] [6] [7] so if you check the content of MyArr[1][0] you're checking the content of the first column (0) of the second row(1), thus 4. in java a matrix doesn't need to have the same column number per row. that takes the name of jagged matrix
30th Aug 2017, 8:22 PM
Michael Vigato
Michael Vigato - avatar
+ 2
you might want to reformulate the question, It's quite difficult to understand what's the matter right now. if you go arr[0][2] = 42; and then System. out. print(arr[0][2]) ; you will get 42
30th Aug 2017, 8:31 PM
Michael Vigato
Michael Vigato - avatar
+ 2
you're welcome :) try to be more complete when asking a question in the first place: you'll get better answers if we can properly understand what is your problem 😁
30th Aug 2017, 8:40 PM
Michael Vigato
Michael Vigato - avatar
+ 1
what do you want know
30th Aug 2017, 7:33 PM
Asiri H
Asiri H - avatar
+ 1
you'll have to provide more of your code for us to help you
30th Aug 2017, 8:03 PM
Michael Vigato
Michael Vigato - avatar
+ 1
and whats wrong with it ?
30th Aug 2017, 8:16 PM
Cain Eviatar
Cain Eviatar - avatar
+ 1
think about it as an insert.
30th Aug 2017, 8:28 PM
Cain Eviatar
Cain Eviatar - avatar
+ 1
thank you❤
30th Aug 2017, 8:33 PM
kais hasan
kais hasan - avatar
+ 1
sure
30th Aug 2017, 8:45 PM
kais hasan
kais hasan - avatar
0
i removed it from the code and the code still work and show 4 as result
30th Aug 2017, 7:39 PM
kais hasan
kais hasan - avatar
0
this is the code... int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; myArr[0][2] = 42; int x = myArr[1][0]; // 4
30th Aug 2017, 8:15 PM
kais hasan
kais hasan - avatar
0
i don't understand why they put"myArr[0][2]=42"
30th Aug 2017, 8:20 PM
kais hasan
kais hasan - avatar
0
i understand this but myArr[0][2] not equal to 42 and i removed it and the code still work
30th Aug 2017, 8:27 PM
kais hasan
kais hasan - avatar