System.out.printf('%1x, %1X', 0xCAFE ) : System.out.printf « java.lang « Java by API






System.out.printf('%1x, %1X', 0xCAFE )

import java.util.Date;
import java.util.Locale;

/**
 * Output:
 
boolean value is true, TRUE
hex value is 71ee6d51, 71EE6D51
hex value is cafe, CAFE
hex value is cafe, CAFE
hex value is 0xcafe, 0XCAFE
value: 3,140000
   
 */

public class MainClass {
  public static void main(String args[]) throws Exception {
    //boolean value is true, TRUE
    System.out.printf("boolean value is %1$b, %1$B\n", true );

    //hex value is b5151397, B5151397
    System.out.printf("hex value is %1$h, %1$H\n", new Date() );
    //hex value 
    System.out.printf("hex value is %1$h, %1$H\n", 0xCAFE );
    //hex value 
    System.out.printf("hex value is %1$x, %1$X\n", 0xCAFE );
    System.out.printf("hex value is %1$#x, %1$#X\n", 0xCAFE );

    System.out.printf( Locale.ITALIAN, "value: %f\n", 3.14 );



  }
}

           
       








Related examples in the same category

1.System.out.printf('%b', String str )
2.System.out.printf('%c', char ch )
3.System.out.printf('%03d', int i )
4.System.out.printf('%e', float )
5.System.out.printf('%03f', float f)
6.System.out.printf('%.2f', float f )
7.System.out.printf('{%07.3f}', float f )
8.System.out.printf('%f', float f )
9.System.out.printf('%g', float f )
10.System.out.printf('%h', float f )
11.System.out.printf('%s', 5)
12.System.out.printf('%s://%s/%s\n', String str1, String str2, String str3)
13.System.out.printf('%1 s...', String str )
14.System.out.printf('%5s', String str)
15.System.out.printf('%-5s', String str) (2)
16.System.out.printf( '%-10.10s %s', String word, int length )
17.System.out.printf('%.5s', String str) (3)
18.System.out.printf('%s', Date date )
19.System.out.printf('%tc', Date date ) (lowercase t, lowercase c)
20.System.out.printf('%tC', Date date ) (lowercase t, uppercase C)
21.System.out.printf('%tD', Date date )
22.System.out.printf('%tF', Date date )
23.System.out.printf('%tr', Date date )
24.System.out.printf('%tR',Date date )
25.System.out.printf('%tT', Date date )
26.System.out.printf('%tz', Date date )
27.System.out.printf('%Tc', Date date ) (Uppercase T, lowercase c)
28.System.out.printf( Locale.CHINA, '%tc', Date date )
29.System.out.printf( Locale.ITALIAN, '%tc', Date date )