PrintStream哪有printf()方法?
只有print和println输出。仔细看看文档先
只有print和println输出。仔细看看文档先
解决方案 »
- 本人第一次到csdn发帖,关于一组数字的算法打印方式
- 问一个Jfreechart关于MultiplePiePlot的字体问题.
- 浮点数范围的疑惑
- 关于C3P0在非web项目下如何使用!
- java中链表的操作
- 在一个List中放若干个Map,怎么穷举出来所有的Map的value的组合
- 求这样的JTextPane!!!!!!!!!先谢了!!!!要多少分都给
- visibroker调试出错“unable to load any jvm”释疑
- 请问在网页中两个Applet如何互相调用
- 请问JAVA如何编写多线程共享一个变量?注意是不同的构造函数做出的线程。
- 拿最后10分提问题,请大家不要见笑……关于private
- scjp: 关于类的初始化顺序
public static void main(String[] args) {
String passed = "1";
String failed = "1"; System.out.printf("passed=%10s; failed=%20s%n", passed, failed);
}
}
在Java命令行下可以编译运行可以吗
以下内容摘自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
等eclipse新的支持tiger语法的版本后你再用eclipse编译吧。呵呵
System.out.printf("passed=%10s; failed=%20s%n", a);
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,我想知道如何可以格式化字符串。
应该这样!!
String[] a = {"1", "2"};
System.out.printf("passed=%10s; failed=%20s%n", a);这样Eclipse可以通过,但Command Line不能通过。
可能是Eclipse设置中忽略了此警告信息。程序代码如下:
public class Test1 {
public static void main(String[] args) {
String[] intArray = {"0","0"}; System.out.printf("passed=%10s; failed=%20s%n", intArray);
}
}