/******************************************************************************
* Example of using - System.out.printf() and 
*                  - String.format()     to format output
******************************************************************************/
public class format 
{
    public static void main(String[] args) 
    {
        System.out.printf("33.758 Rounded= \t %6.2f \n", 33.758);                      //rounded up
        System.out.printf("33.752 Rounded= \t %6.2f \n", 33.752);                      //rounded down
        System.out.printf("%04d %2d %3.2f %6.2f     \n", 123, 123, 4321.10, 4321.10); 
        System.out.printf("%d, %f, %x, %o,          \n", 5, 4321.10, 28, 255); 
        System.out.printf("%+4.2f -- %10.4f         \n", 27.5,  33.75);                //smaller and larger
        System.out.printf("%s%.2f                   \n", "The price is $", 3.0);
        System.out.printf("%s%06.2f                 \n", "The price is $", 3.0);

        String f = String.format("%1$c, %1$4d, %1$4x \n", 97);       //targeting the same field
        System.out.print(f);
     }
}