int t = 5;
System.out.printf("%3x ",t);
String outString = String.format("%d",t);
编译不过,它参数一定要object 型,我现在想格式输出。比如c语言里的printf("%5x",t);
怎么解决啊?
在线等。

解决方案 »

  1.   

    你的程序没有问题哦,你用的printf这些api是1.5才有的,应该是你jdk的版本不对。。你cmd下,使用java -version看看你jdk的版本
      

  2.   

        int   t   =   5;
        DecimalFormat dataFormat = new DecimalFormat("000");
        System.out.println(dataFormat.format(t));
      

  3.   

    shan1119老兄:
    DecimalFormat 是十进制,不能做八进制或十六机制的格式准换吧。cocosunshine老兄: 我用的api就是1.5的。
      

  4.   

    jdk1.5 or later,具有自动拆装箱功能楼主用的啥ide,像eclipse,可以指定用比安装的jdk版本更低的版本来编译,比如装了1.5,实际指定 了1.4,1.5的功能就不能用了
      

  5.   

    我用1.5的没有问题,如果你用ide,你查看一下是不是使用了1.5的。
      

  6.   

    String outString = String.format("%5x",t); 
    System.out.printf(outString); 测试没有问题可能是你的版本不对吧检查一下你的IDE用的JDK的版本
      

  7.   

    谢谢大家,我用的是eclipse 3.0,原因在于eclipse 3.0不支持1.5的一些功能。
      

  8.   

    int   t   =   5; 
    System.out.printf("%3x   ",t); 首先t是int型数据,是最原始数据类型
    不是Object
    你要把int数据转换成Integer再输出
    System.out.printf("%3x   ",new Integer(i));    //这样试试吧