Source of FieldWidthTest.java


  1: // Fig. 28.12: FieldWidthTest.java
  2: // Right justifying integers in fields.
  3: 
  4: public class FieldWidthTest 
  5: {
  6:    public static void main( String args[] )
  7:    { 
  8:       System.out.printf( "%4d\n", 1 );
  9:       System.out.printf( "%4d\n", 12 );
 10:       System.out.printf( "%4d\n", 123 );
 11:       System.out.printf( "%4d\n", 1234 );
 12:       System.out.printf( "%4d\n\n", 12345 ); // data too large 
 13: 
 14:       System.out.printf( "%4d\n", -1 );
 15:       System.out.printf( "%4d\n", -12 );
 16:       System.out.printf( "%4d\n", -123 );
 17:       System.out.printf( "%4d\n", -1234 ); // data too large 
 18:       System.out.printf( "%4d\n", -12345 ); // data too large 
 19:    } // end main
 20: } // end class RightJustifyTest
 21: 
 22: 
 23: 
 24: /**************************************************************************
 25:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 26:  * Pearson Education, Inc. All Rights Reserved.                           *
 27:  *                                                                        *
 28:  * DISCLAIMER: The authors and publisher of this book have used their     *
 29:  * best efforts in preparing the book. These efforts include the          *
 30:  * development, research, and testing of the theories and programs        *
 31:  * to determine their effectiveness. The authors and publisher make       *
 32:  * no warranty of any kind, expressed or implied, with regard to these    *
 33:  * programs or to the documentation contained in these books. The authors *
 34:  * and publisher shall not be liable in any event for incidental or       *
 35:  * consequential damages in connection with, or arising out of, the       *
 36:  * furnishing, performance, or use of these programs.                     *
 37:  *************************************************************************/