001package edu.pdx.cs410J.datesAndText;
002
003import java.io.PrintStream;
004import java.util.Calendar;
005
006/**
007 * Demonstrated J2SE 1.5's facilities for <code>printf</code>-style
008 * formatting. 
009 *
010 * @see java.util.Formatter
011 *
012 * @author David Whitlock
013 * @version $Revision: 1.2 $
014 * @since Summer 2004
015 */
016public class Formatting {
017
018  /**
019   * Formats a number of different kinds of data using J2SE 1.5's
020   * formatting facilities.
021   */
022  public static void main(String[] args) {
023    PrintStream out = System.out;
024    out.printf("%s%n", "Hello World");
025
026    Calendar today = Calendar.getInstance();
027
028    out.printf("Today's date is: %tm/%td/%tY%n", today, today, today);
029    out.printf("The current time is: %tl:%tM %tp%n", today, today, today);
030
031    out.printf("%f/%.2f = %f%n", 2.0, 3.0, (2.0/3.0));
032
033    for (int i = 0; i < 3; i++) {
034      out.printf("%5s%5s%5s%n", i, i+1, i+2);
035    }
036
037    out.printf("%-10s%s%n", "left", "right");
038  }
039
040}