// FormatterTests.java (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2004-09-19 File created. // 2005-06-02 Last modification. // This program tests class Formatter. // Mostly this program tests the System.out.printf() method which // works as specified in the documentation of the Formatter class. import java.util.* ; class FormatterTests { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; Formatter text_to_print = new Formatter() ; text_to_print.format( " %d ", 3 ) ; text_to_print.format( " %x ", 33 ) ; // Hexadecimal printing long current_time_ticks = System.currentTimeMillis() ; text_to_print.format( " %tc ", current_time_ticks ) ; System.out.print( "\n" + text_to_print + "\n" ) ; System.out.printf( "\n %tD is %%tD format", current_time_ticks ) ; System.out.printf( "\n %tF is %%tF format", current_time_ticks ) ; System.out.printf( "\n %tT is %%tT format", current_time_ticks ) ; System.out.printf( "\n\n 1234 in hexadecimal form is %04X", 1234 ) ; System.out.printf( "\n 12345 in too narrow printing field is %3d", 12345); System.out.printf( "\n 4FFE with lowercase digits is %06x", 0x4FFE ) ; System.out.printf( "\n %%g prints %g", 1.234e-10 ) ; System.out.printf( "\n 123.456 in hexadecimal form is %a", 123.456 ) ; System.out.printf( "\n 1234567.89 with specifier %%,.3f is %,.3f", 1234567.89 ) ; System.out.printf( "\n %c is a character. ", 'c' ) ; System.out.printf( "\n Date object printed with %%s is %s", new Date( 2, 6, 2005 ) ) ; System.out.printf( "\n Object object printed with %%s is %s", new Object() ) ; System.out.printf( "\n Current date is %tF", current_time_ticks ) ; System.out.printf( "\n Current time is %tT", current_time_ticks ) ; } }