Using character and string conversion characters. - Java Language Basics

Java examples for Language Basics:Number Format

Description

Using character and string conversion characters.

Demo Code

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
   } 
}

Result


Related Tutorials