编程资料集中营
 | 网站首页 | 文章中心 | 编程资料2 | 软件下载 | BT下载 | 八卦星闻 | 音乐在线 | 在线游戏 | 免费电影 | 给我留言 | 
          ★★★
【字体:
进入问吧

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

作者:admin    文章来源:网络    点击数:    更新时间:2006-12-27    

JDK5.0的11个主要新特征-Java技术

yee

public Employee clone() { ... }

...
Employee cloned = e.clone();

11 格式化I/O(Formatted I/O)

  增加了类似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

文章录入:admin    责任编辑:admin 
高级搜索
编程资料集中营