FAQs on the exercise Traversing 2D Arrays: Introduction
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
Happy New Year everyone!
Really hoped to finish this course by the end of 2020, but made only to Learn Java[ 11 ][ 6 ] (or [ 10 ][ 5 ] when taking into account that indeces start from 0).
The third exercise:
Store the number of columns in intMatrix into a variable called columns and the number of rows in intMatrix into a variable called rows .
was a bit confusing, because I couldn’t understand why I would I do something twice (since the same thing was covered in exercises 1 and 2).
And I’m sure glad that Java wasn’t my first language to learn. There is a great deal of mindbending with all the classes, constructors, polymorphism keywords and boilerplate code.
this lesson in particular was really well fleshed out. But there is a lot of seemingly obsolete content. I reads like you try to explain the concept of nested loops 3 more times after the last lesson. I personally find it pretty easy to grasp. Maybe that is just me.
I really wished you would have put more afford like this in other more complex topics like polymorphism.
I am confused with intMatrix.length and intMatrix[0].length, because they both print “5”. So why are there two different formats if they are asking for the same thing? Thanks!
intMatrix.length and intMatrix[0].length do not refer to the same thing. intMatrix is an array of arrays of integers.
so intMatrix.length is the length of the “outer” array - it tells you how many arrays are in intMatrix.
intMatrix[0] is the first array in intMatrix (meaning the array at an index of zero for intMatrix)
so intMatrix[0].length is the length of this “inner” array - which is how many integers there are in intMatrix[0]
Thanks so much for your detailed answer! It makes sense to me now!
I just realized that I made a mistake on the printout, I literally asked it to print the same thing, that’s why they both printed 5…
What are do-while loops? It seems only while loops had been covered in the course previously
Since enhanced for loops only use the element of the arrays, it is a bit more cumbersome to keep track of which index we are at. This same idea applies to while and do-while loops as well.
In a do-while loop, the expression for the condition is evaluated at the bottom. This means the do-while loop will execute at least once even if the condition is false.
A while loop checks the condition at the top. If the condition is false at the very beginning, a while loop may not execute even once.
The number of columns is the same as the number of elements within a subarray and the number of rows is the same as the number of subarrays in a 2D array.
In Step 2, you figured out the length of the subarrays and stored it in a variable named subArrayLength (in your screenshot). This is the same as the number of columns in intMatrix, so for Step 3, you can declare and initialize a new variable as
int columns = subArrayLength;
Similarly, in Step 1, you figured out the number of subarrays and stored it in a variable named numSubArrays (in your screenshot). This is the same as the number of rows in intMatrix, so for Step 3, you can declare and initialize a new variable as
int rows = numSubArrays;
Before proceeding, make sure you think on why the above assignments make sense. Looking at the intMatrix in your screenshot, can you visualize why numSubArrays is the same as rows AND why subArrayLength corresponds to columns?
This lecture is very very badly explained and exhuasted all my energy need to improve your explaination of lessons
This lesson is very badly explained please improve this lesson because I understand nothing in this lesson strong text Traversing 2D Arrays: Introduction