
本站地址:http://www.bajiao123.com

JDK5.0的11个主要新特征-Java技术
yeepublic Employee clone() { ... }
...
Employee cloned = e.clone();
增加了类似C的格式化输入输出,简单的例子:
public class TestFormat{
public static void main(String[] args){
int a = 150000, b = 10;
float c = 5.0101f, d = 3.14f;
System.out.printf("%4d %4d%n", a, b);
System.out.printf("%x %x%n", a, b);
System.out.printf("%3.2f %1.1f%n", c, d);
System.out.printf("%1.3e %1.3e%n", c, d*100);
}
}
输出结果为:
150000 10
249f0 a
5.01 3.1
5.010e+00 3.140e+02下面是一些格式化参数说明(摘自Core Java 2 Volume I - Fundamentals, Seventh Edition)
Table 3-5. Conversions for printf
Conversion Character
Type
Example
d
Decimal integer
159
x
Hexadecimal integer
9f
o
Octal integer
237
f
Fixed-point floating-point
15.9
e
Exponential floating-point
1.59E+01
g
General floating-point (the shorter of e and f)
a
Hexadecimal floating point
0x1.fccdp3
s
String
Hello
c
Character
H
b
Boolean
TRUE
h
Hash code
42628b2
tx
Date and time
See Table 3-7
%
The percent symbol
%
n
The platform-dependent line separator
上一页 [1] [2] [3] [4] [5] [6] [7] [8] 下一页
本站地址:http://www.bajiao123.com

