Multi-Dimensional Arrays in Java: Computer Courses
Multi-Dimensional Arrays in Java: Computer Courses
Multi-Dimensional Arrays in Java: Computer Courses
Home
Beginners Computing
Excel to 2003
Web Design
Beginners PHP
C# .NET
A multi dimensional array is one that can hold all the values above. You set them up like this:
The first for loop is used for the rows; the second for loop is for the columns. The first time
round the first loop, the value of the variable i will be 0. The code inside of the for loop is
another loop. The whole of this second loop will be executed while the value of the variable i is
0. The second for loop use a variable called j. The i and the j variables can then be used to access
the array.
aryNumbers[ i ][ j ]
So the two loop system is used to go through all the values in a multi-dimensional array, row by
row.
Exercise J
Finish off the program above where we are writing a program to print out all the values from the
spreadsheet. Your Output window should look something like this when you're done:
Answer to Exercise J
Multi-dimensional arrays can be quite tricky, but mainly because it's hard to keep track of all
your rows and columns! In the next part, you'll learn about array lists.