/*
* Created on 2004-6-1
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author pal
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
*
* 在Delphi中用习惯 Format() 函数, 好在 Java 1.5.0 中支持了:)
*
*
*/
import java.util.*;
public class TestFormatter
{
public static void main(String[] args)
{
String str1 = "aa";
String str2 = "eeee";
Integer a = new Integer(65);
// Char
Object[] objs = new Object[1];
objs[0] = a;
// %n 回车换行
System.out.printf("char: %c %n", objs);
// Integer
Object[] objs1 = new Object[5];
objs1[0] = a;
objs1[1] = a;
objs1[2] = a;
objs1[3] = a;
String str = String.format("char: %c integral: %d octal: %o hex: %x %n", objs1);
System.out.println(str);
// String
Object[] objs2 = new Object[3];
objs2[0] = new String("syd");
objs2[1] = new String("fly");
System.out.printf("reason: %s (noted by %s) %n", objs2);
// Date
Object[] objs3 = new Object[1];
objs3[0] = new Date();
//文档中的 tL 好像没有实现, 可以参考jdk厡代码
System.out.printf("%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %1$tN %n", objs3);
System.out.printf("%1$tF %1$tT %n", objs3);
// Float
Object[] objs4 = new Object[1];
objs4[0] = new Float(6.0);
StringBuffer buff = new StringBuffer();
Formatter ft = new Formatter(buff);
ft.format("a float numberic: %f %n", objs4);
System.out.println(buff.toString());
}
}