输出数据的格式控制
输出控制符
针对的数据类型
%d
int,long int,short,byte
%x,%#x,%X,%#X
int,long int
%c
char
%f
float,double
%s
string
备注:
在java中没有%ld & %lf,比如float & double 都用%f输出,这是与C/C++不同的
public class TestOutData {
public static void main(String []args) {
int i = 46;
char j ='a';
float k = 3.56412f;
double m = 3.8;
String str = "Hello world!";
/*
2017-12-31 23:32:54 java version 1.8.0_111-b14
输出结果是:
*/
System.out.printf("i = %d\n",i);//i = 46
System.out.printf("i = %x\n",i);//i = 2e
System.out.printf("i = %X\n",i);//i = 2E
System.out.printf("i = %#x\n",i);//i = 0