整数转换字符包括以下内容。
字符 | 描述 |
---|---|
%d | 整数 |
%o | 八进制 |
%X | 十六进制 |
%X | 十六进制 |
public class Demo { public static void main(String[] args) throws Exception { System.out.printf( "Integer: %d\n", 889 ); System.out.printf( "Negative Integer: %d\n", -78 ); System.out.printf( "Octal: %o\n", 677 ); System.out.printf( "Hexadecimal: %x\n", 56 ); System.out.printf( "Hexadecimal: %X\n", 99 ); } }
输出结果
Integer: 889 Negative Integer: -78 Octal: 1245 Hexadecimal: 38 Hexadecimal: 63