Mega Code Archive

 
Categories / Java Tutorial / Development
 

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

public class MainClass {    public static void main( String args[] )     {       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" );    } } false true FALSE Hashcode of "hello" is 5e918d2 Hashcode of "Hello" is 42628b2 Hashcode of null is NULL Printing a % in a format string Printing a new line next line starts here