Java Reference
In-Depth Information
LISTING 8.13
//********************************************************************
// TwoDArray.java Author: Lewis/Loftus
//
// Demonstrates the use of a two-dimensional array.
//********************************************************************
public class TwoDArray
{
//-----------------------------------------------------------------
// Creates a 2D array of integers, fills it with increasing
// integer values, then prints them out.
//-----------------------------------------------------------------
public static void main (String[] args)
{
int [][] table = new int [5][10];
// Load the table with values
for ( int row=0; row < table.length; row++)
for ( int col=0; col < table[row].length; col++)
table[row][col] = row * 10 + col;
// Print the table
for ( int row=0; row < table.length; row++)
{
for ( int col=0; col < table[row].length; col++)
System.out.print (table[row][col] + "\t");
System.out.println();
}
}
}
OUTPUT
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49
Search WWH ::




Custom Search