Learning Arrays

From: Jo Campbell (jocampbell_at_maine.rr.com)
Date: 11/28/04

  • Next message: Andrew Thompson: "Re: Learning Arrays"
    Date: Sun, 28 Nov 2004 01:29:49 GMT
    
    

    Hi, I am just learning arrays and I am trying to get this 2D array to print
    out like this:

    0 1 2 3 4 5 6
    0 1 2 3 4 5 6
    0 1 2 3 4 5 6
    0 1 2 3 4 5 6
    0 1 2 3 4 5 6

    but insteads it prints out like this: 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4
    5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6

    I can get it to work with system.out.println but I need to use a
    JOptionPane.showMessageDialog box as I have attempted to do. Any ideas?
    (my code is below) Thanks!!!!!!!!!!

    import javax.swing.*;

    public class array5by7{

     public static void main (String args[]){

      String outputString = "";

      int table[][] = new int [5][7];

      for (int row=0; row<table.length; row++)
      {
       for (int col = 0; col <table[row].length; col++)
       table[row][col] = 0 + col;
      }

      for (int row=0; row<table.length; row++)
      {
       for (int col = 0; col<table[row].length; col++)
        outputString += (table[row][col] + " ");
       }

      JOptionPane.showMessageDialog (null, outputString + "\n");

      }

    }


  • Next message: Andrew Thompson: "Re: Learning Arrays"