我可以做这个:
public class first{
public static void main (String[] args){
String message = String.format("%s, next year you'll be % +d", "Michael", 37);
System.out.printf(message);
}
}
不工作:我收到运行时错误:
Exception in thread "main" java.util.IllegalFormatFlagsException: Flags = '+ '
at java.util.Formatter$FormatSpecifier.checkNumeric(Unknown Source)
at java.util.Formatter$FormatSpecifier.checkInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at first.main(first.java:3)
好吧,我只能使用空格符号或+。然后它正在工作。但是我怎样才能将两者结合起来呢?