1  public class WorldPopulation
  2  {
  3     public static void main(String[] args)
  4     {
  5        final int ROWS = 6;
  6        final int COLUMNS = 7;
  7  
  8        int[][] data = 
  9           { 
 10              { 106, 107, 111, 133, 221, 767, 1766 },
 11              { 502, 635, 809, 947, 1402, 3634, 5268 }, 
 12              { 2, 2, 2, 6, 13, 30, 46 }, 
 13              { 163, 203, 276, 408, 547, 729, 628 },
 14              { 2, 7, 26, 82, 172, 307, 392 },
 15              { 16, 24, 38, 74, 167, 511, 809 }
 16           };
 17  
 18        String[] continents = 
 19           { 
 20              "Africa", 
 21              "Asia", 
 22              "Australia",
 23              "Europe", 
 24              "North America", 
 25              "South America" 
 26           };
 27  
 28        System.out.println("                Year 1750 1800 1850 1900 1950 2000 2050");
 29        
 30        // Print data
 31        
 32        for (int i = 0; i < ROWS; i++)
 33        {      
 34           // Print the ith row
 35           System.out.printf("%20s", continents[i]);
 36           for (int j = 0; j < COLUMNS; j++)
 37           {
 38              System.out.printf("%5d", data[i][j]);
 39           }
 40           System.out.println(); // Start a new line at the end of the row
 41        }
 42  
 43        // Print column totals
 44  
 45        System.out.print("               World");
 46        for (int j = 0; j < COLUMNS; j++) 
 47        {
 48           int total = 0; 
 49           for (int i = 0; i < ROWS; i++)
 50           {
 51              total = total + data[i][j];
 52           }
 53           System.out.printf("%5d", total);         
 54        }
 55        System.out.println(); 
 56     }
 57  }