/*****************************************************************
** TableOfCubes - same as TableOfSquares, except...
**
** This program generates a table of cubes for the integers
** 0 through 10.  The main new feature is the ability to control
** the look of the table.  To assist, the following method (or
** function) is used:
**
** formatInt    - format an integer into a string, padding to the
**                left with spaces to create a string of a given
**                length
**
** The following output is generated:
**
**    =============
**     x  Cube of x
**    --- ---------
**      0         0
**      1         1
**      2         8
**      3        27
**      4        64
**      5       125
**      6       216
**      7       343
**      8       512
**      9       729
**     10      1000
**    =============
**
** (c) Scott MacKenzie, 2000                             
******************************************************************/
import java.io.*;

public class TableOfCubes
{
   public static void main(String[] args)
   {
      System.out.print("=============\n"
                    +  " x  Cube of x\n"
                    +  "--- ---------\n");      
      int x = 0;
      String s1;
      String s2;
      while (x <= 10)
      {
         s1 = formatInt(x, 3);
         s2 = formatInt(x * x * x, 10);
         System.out.println(s1 + s2);
         x++;
      }
      System.out.println("=============\n");
   }

   // format integer 'i' as a string of length 'len' (pad left with spaces)
   public static String formatInt(int i, int len)
   {
      String s = "" + i;
      while (s.length() < len)
         s = " " + s;
      return s;
   }
}

