/* Pixels.java by Craig Persiko
   Demonstrates use of a 2-dimensional array of integers
*/

class Pixels
{
  public static void main(String[] args)
  {
    int[][] pixels = new int[4][6];  // reduced to simplify testing & output

    int[] headerRow = new int[6];

    // store the column numbers in the header row (used to label output)

    for(int c=0; c < headerRow.length; c++)
      headerRow[c] = c;

    clearScreen(pixels);
    pixels[2][3] = 7;

    // display a header row:

    System.out.print("Col# :\t");
    outputRow(headerRow);
    // display each row of the array

    for(int r=0; r < pixels.length; r++)
    {
      System.out.print("\nRow " + r + ":\t");
      outputRow(pixels[r]);
    }
    System.out.println();
  }

  // make every element of the 2-D array store 0.

  static void clearScreen(int[][] p)
  {
    int x, y;

    for (y=0; y < p.length; y++)
    {
      for (x=0; x < p[y].length; x++)
        p[y][x] = 0;
    }
  }

  // display all "size" elements of the 1-D array p.

  static void outputRow(int[] p)
  {
    int x;

    for (x=0; x < p.length; x++)
      System.out.print(p[x] + " ");
  }
}

/* Output:

Col# :  0 1 2 3 4 5
Row 0:  0 0 0 0 0 0
Row 1:  0 0 0 0 0 0
Row 2:  0 0 0 7 0 0
Row 3:  0 0 0 0 0 0

*/


syntax highlighted by Code2HTML, v. 0.9