Java examples for Language Basics:Number Format
Using character and string conversion characters.
public class Main { public static void main(String[] args) { //from w w w. j a v a2 s .co m char character = 'A'; // initialize char String string = "This is also a string"; // String object Integer integer = 1234; // initialize integer (autoboxing) System.out.printf("%c\n", character); System.out.printf("%s\n", "This is a string"); System.out.printf("%s\n", string); System.out.printf("%S\n", string); System.out.printf("%s\n", integer); // implicit call to toString } }