PrintStream哪有printf()方法?
只有print和println输出。仔细看看文档先

解决方案 »

  1.   

    public class Test {
        public static void main(String[] args) {
            String passed = "1";
            String failed = "1";        System.out.printf("passed=%10s; failed=%20s%n", passed, failed);
        }
    }
    在Java命令行下可以编译运行可以吗
      

  2.   

    To  tomcatjava(小鱼儿) :
    以下内容摘自JDK5.0 Documentation
    printf
    public PrintStream printf(String format,
                              Object... args)
    A convenience method to write a formatted string to this output stream using the specified format string and arguments. 
    An invocation of this method of the form out.printf(format, args) behaves in exactly the same way as the invocation      out.format(format, args) Parameters:
    format - A format string as described in Format string syntax
    args - Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by the Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion. 
    Returns:
    This output stream 
    Throws: 
    IllegalFormatException - If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification. 
    NullPointerException - If the format is null
    Since: 
    1.5 
      

  3.   

    out里应该没有这个printf的方法的。应该是println 或者print
      

  4.   

    偶用的是jdk1.4,没用过1.5的,不了解
      

  5.   

    应该是你在Eclipse中使用的是JDK1.4,所以无法支持你的类。又或者你的Eclipse可能对JDK5.0支持得不好
      

  6.   

    这根eclipse没有关系,因为你用的是jdk5的语法,而eclipse不支持jdk5,所以,他编译的时候用的1.4target,故此报错。(你的机器上一定装的是jdk5.0就是了)
    等eclipse新的支持tiger语法的版本后你再用eclipse编译吧。呵呵
      

  7.   

    应该这样!!String[] a = {"1", "2"};
    System.out.printf("passed=%10s; failed=%20s%n", a);
      

  8.   

    改为如下程序,Eclipse可以通过,但命令行还是不行。
    public class Test2 {
        public static void main(String[] args) {        
    String[] sa = { "1", "1"};
    String s = String.format("passed=%10s; failed=%20s%n", sa);
    System.out.println(s);
        }
    }我刚学Java,我想知道如何可以格式化字符串。
      

  9.   

    to  cuizm(射天狼) 
    应该这样!!
    String[] a = {"1", "2"};
    System.out.printf("passed=%10s; failed=%20s%n", a);这样Eclipse可以通过,但Command Line不能通过。
      

  10.   

    命令行编译中系统只是发出一个警告信息,程序仍然可以运行。
    可能是Eclipse设置中忽略了此警告信息。程序代码如下:
    public class Test1 {
        public static void main(String[] args) {
            String[] intArray = {"0","0"};           System.out.printf("passed=%10s; failed=%20s%n", intArray);
        }
    }