/home/wpollock1/public_html/Java/PrintfDemo.java

// PrintfDemo.java - a demo that shows how to format using printf.
// (Prior to Java 5 we used legacy classes such as NumberFormatter.)
//
// See Java API docs for java.util.Formatter class for details on
// the syntax of the "format" string used with printf.  In brief,
// for each argument after the required format string, those arguments
// will be substituted into the format string using a "conversion":
//   %b  a boolean
//   %c  a character
//   %s  a string
//   %d  an integer (including BigInteger objects)
//   %o  an integer, in octal
//   %h  an integer, in hexadecimal ("%H" is the same but with uppercase)
//   %f  a floating point value
//   %n  an end-of-line character sequence (platform-specific)
//   %%  a literal percent symbol
//
//  (Between the '%' and the letter indicating the type of conversion,
//  various optional flags can appear.)
//
// Written 1/2005 (updated 3/2019) by Wayne Pollock, Tampa Florida USA.

class PrintfDemo
{
    public static void main ( String [] args )
    {
        double someDbl = 3.6666666665;
        int someInt = 26;
        int someOtherInt = 66;
        boolean someBool = true;
        char someChar = 'A';
        String someString = "Hymie";

        System.out.println( "original double:  "  + someDbl );
        System.out.println( "original int:     "  + someInt );
        System.out.println( "original boolean: "  + someBool );
        System.out.println( "original char:    "  + someChar );
        System.out.println( "original string:  "  + someString );

        System.out.printf( "%n\t---Using printf:---%n%n" );

        System.out.printf( "double: %%f=%f, %%5.2f=%5.2f, %%05f=%05f, "
           + "%%05.2f=%05.2f, %%e=%4.1e %n%n", someDbl, someDbl,
            someDbl, someDbl, someDbl );

        System.out.printf( "int: %%d=%d, '%%5d'='%5d', '%%-5d'='%-5d', "
           + "%%o=%o, %%h=%h, %%H=%H, %%c=%c %n%n", someInt, someInt, someInt,
           someInt, someInt, someInt, someInt );
        System.out.printf( "other int: %%d=%d, %%c=%c %n%n", someOtherInt,
           someOtherInt );

        System.out.printf( "char: %%c=%c %n%n", someChar );

        System.out.printf( "string (%%S):    My name is '%S'.%n", someString );
        System.out.printf( "string (%%10s):  My name is '%10s'.%n", someString );
        System.out.printf( "string (%%-10s): My name is '%-10s'.%n%n",
            someString );

        System.out.printf( "boolean: '%%-5b'='%-5b', '%%-5B'='%-5B' %n%n",
           someBool, someBool );

        System.out.printf( "hashcode: %%h=%h %n", new Object() );
    }
}