在printf中使用标志时,我需要遵循什么特定顺序吗?
1.System.out.printf("%+04d + %s ", 12, "a");// include sign then pad zeros
2.System.out.printf("\n%04+d + %s ", 12, "a");// pad zeros then include sign
3.System.out.printf("\n%+-4d + %s ", 12, "a");// include sign then left justify
4.System.out.printf("\n%-4+d + %s ", 12, "a");// left justify then include sign
The answer is:
+012 + a
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '0'
+12 + a
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = '-'
谢谢。
答案 0 :(得分:0)
是顺序问题,这就是为什么您会因某些组合而异常:
% [flags][width][.precision] conversion-character (square brackets denote optional parameters)
谢谢