Monday, January 3, 2011

Java Tutorial #19

0
Introduction to Multidimensional Arrays
Java also allows two dimensional and multidimensional size arrays. And the simplest form of multidimensional array is the two dimensional array. Its general equation is:

Type array_name[1st Index][2nd Index] = { {a, b, c } , {d, e, f} };

Where: 1st index is the number of row, 2nd index is the number of column. a, b and c are the elements of the first row (which is row 0) and d, e and f are the elements of the second row (which is row1).

Note: All index start counting from 0.

Ex.

int input[ ] [ ] = { {1, 2, 3} , {4, 5, 6} };

Just look at the table below.


Array “input”
Column 0
Column 1
Column 2
Row 0
1
2
3
Row 1
4
5
6

The table represents the array input. The array “input” is a two-dimensional array. It composed of many elements found on a separate row and column. Unlike the single dimensional array which contains a columns only. The array initializer above is also the same to this one.

input[0] [0] = 1;                                                input[1] [0] = 4;
input[0] [1] = 2;                                                input[1] [1] = 5;
input[0] [2] = 3;                                                input[1] [2] = 6;


Just look at the table, the values above and the array initializer. You will get it by looking to those things.



No Response to "Java Tutorial #19"

Post a Comment