+ 2

# int[ ][ ] myArr = { {1, 2, 3}, {4}, {5, 6, 7} }; myArr = 42; int x = myArr; // 4

I don't get how myArr=42 Shouldn't myArr=3? I must be missing something super basic, but can't figure it out

5th Jul 2017, 12:49 PM
Sheevika
+ 3
here we have a 3 dimensional array . 1st element - {1,2,3} // counted as 0 here sub elements are - 1- // counted 0 2- // counted 1 3- // counted 2; so here myArr is 1 myArr is 2 myArr is 3 for second element we have {4} // taken as 1 so here only one element is there so there is only one possible value myArr = 4 for third we have {5,6,7} // taken as 2 here there are again 3 possibilities myArr is 5 myArr is 6 myArr is 7 // hope that helps .
5th Jul 2017, 1:04 PM
RZK 022 + 2
myarr=42 here in this line 42 is assigned in the array.. and replaces 3..
5th Jul 2017, 1:24 PM
Мг. Кнап🌠 + 1
myArr=42 changes the value of myArr, wich was 3, to 42. In Java there is '=' and '=='. '=' MODIFY without VERIFY the value of the variable on the LEFT of it. '==' VERIFY without MODIFY both values (left and right) Do you understand ?
5th Jul 2017, 1:11 PM
Jojo
0
If myArr=42 is part of your code, it's an like i=3; It's an affectation.
5th Jul 2017, 12:52 PM
Jojo
0
Still not getting it, sorry. What is the purpose of that line of code? It was in the tutorial without any explanation
5th Jul 2017, 12:59 PM
Sheevika
0
thanks :) But, my problem is, I don't understand how myArr = 42. According to what you just showed me, and what i understood from the lesson, given this array, myArr should be equal to 3. But for some reason it says 42 on the tutorial
5th Jul 2017, 1:08 PM
Sheevika
0
Yes, thanks Jojo. One more question though: so basically this is a piece of code that doesn't do anything here? (except say that myArr is equal to 42).
5th Jul 2017, 1:23 PM
Sheevika
0
Nothing will output
5th Jul 2017, 1:24 PM
Jojo
0
Is that alright ? Ask if it's not !
5th Jul 2017, 1:25 PM
Jojo