FAQ: 2D Arrays: Java - Traversing 2D Arrays: Introduction

This community-built FAQ covers the “Traversing 2D Arrays: Introduction” exercise from the lesson “2D Arrays: Java”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Java

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 (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 (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

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.

Hi all,

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.

Have a look at the last paragraph of this page:

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.

1 Like