Source of CharStringConversion.java


  1: // Fig. 28.5: CharStringConversion.java
  2: // Using character and string conversion characters.
  3: 
  4: public class CharStringConversion 
  5: {
  6:    public static void main( String args[] )
  7:    { 
  8:       char character = 'A';  // initialize char
  9:       String string = "This is also a string";  // String object
 10:       Integer integer = 1234;  // initialize integer (autoboxing)
 11: 
 12:       System.out.printf( "%c\n", character );
 13:       System.out.printf( "%s\n", "This is a string" );
 14:       System.out.printf( "%s\n", string );
 15:       System.out.printf( "%S\n", string );
 16:       System.out.printf( "%s\n", integer ); // implicit call to toString
 17:    } // end main 
 18: } // end class CharStringConversion
 19: 
 20: 
 21: /**************************************************************************
 22:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 23:  * Pearson Education, Inc. All Rights Reserved.                           *
 24:  *                                                                        *
 25:  * DISCLAIMER: The authors and publisher of this book have used their     *
 26:  * best efforts in preparing the book. These efforts include the          *
 27:  * development, research, and testing of the theories and programs        *
 28:  * to determine their effectiveness. The authors and publisher make       *
 29:  * no warranty of any kind, expressed or implied, with regard to these    *
 30:  * programs or to the documentation contained in these books. The authors *
 31:  * and publisher shall not be liable in any event for incidental or       *
 32:  * consequential damages in connection with, or arising out of, the       *
 33:  * furnishing, performance, or use of these programs.                     *
 34:  *************************************************************************/