Using the b, B, h, H, % and n conversion characters. - Java Language Basics

Java examples for Language Basics:Number Format

Description

Using the b, B, h, H, % and n conversion characters.

Demo Code



public class Main 
{
   public static void main(String[] args) 
   {//from   w  w  w .ja  v  a2 s  . c  o  m
      Object test = null;
      System.out.printf("%b\n", false);
      System.out.printf("%b\n", true);
      System.out.printf("%b\n", "Test");
      System.out.printf("%B\n", test);
      System.out.printf("Hashcode of \"hello\" is %h\n", "hello");
      System.out.printf("Hashcode of \"Hello\" is %h\n", "Hello");
      System.out.printf("Hashcode of null is %H\n", test);
      System.out.printf("Printing a %% in a format string\n");
      System.out.printf("Printing a new line %nnext line starts here");
   } 
}

Result


Related Tutorials