/**
 * Print out histogram made of stars for each element in the array. We
 * tried two algorithms, one with direct printing and one by creating a
 * String. Both are reasonable style. 
 * Wed Mar 2 2006
 */
public class HistogramLoop
{
  public static void main(String[] args)
  {
    int totalCans = 0;
    int[] cansSold = {6, 8, 11, 18, 20, 17, 14, 10, 5, 2};

    // Take 1: print stars out directly
    for (int i = 0; i < cansSold.length; i++)
    {
      for (int j = 0; j < cansSold[i]; j++) {
          System.out.print("*");
      }
      System.out.println(); // System.out.print("\n"):     
      // We can get a new line either with the println method or by
      // printing out the end of line character.
    }
    System.out.println();
    
    // Take 2: construct string of stars, then print out whole line at
    // once.
    for (int i = 0; i < cansSold.length; i++)
    {
      String lineOfStars = "";
      for (int j = 0; j < cansSold[i]; j++) {
          lineOfStars += "*";
      }
      System.out.println(lineOfStars);      
    }
    System.out.println();
  }
}

