UNB/ CS/ David Bremner/ teaching/ java/ Table2.java
public class Table2
{  public static void main(String[] args)
   {  final int COLUMN_WIDTH = 10;
   
      int[][] powers = new int[10][8];
      for (int i = 0; i < 10; i++)
         for (int j = 0; j < 8; j++)
            powers[i][j] = (int)Math.pow(i + 1, j + 1);
            
      printTable(powers, COLUMN_WIDTH);
   }

   /**
      Prints a two-dimensional array of double
      @param table the values to be printed
      @param width the column width
   */
   public static void printTable(int[][] table, int width)
   {  for (int i = 0; i < table.length; i++)
      {  for (int j = 0; j < table[i].length; j++)
         {  System.out.print(format(table[i][j], width));
         }
         System.out.println();
      }
   }

   /**
      Formats an integer to fit in a field of constant width
      @param n the integer to format
      @param width the field width
      @return a string of length width, consisting of 
      leading spaces followed by the number n
   */
   public static String format(int n, int width)
   {  String nstr = "" + n;

      // pad with spaces

      while (nstr.length() < width)
         nstr = " " + nstr;

      return nstr;
   }
}