1
我有這樣的代碼,我想,如下所示格式化輸出,但是當我啓動程序,達到對printf,它停止並給出錯誤Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.String
用printf
variables:
itemcode=integer
selecteditems=string
perkg=double
userkg=string
quantity-integer
dry=string
total=double
格式化輸出的java注意:這些是for循環的可變變量。
System.out.printf("%-4d %-13s %8.2f %8.2f %-8d %-10s %8.2f %n", itemcode,
selecteditems, per_kg, userkg, quantity, dry, total);
這將有助於瞭解這些變量的值和類型的 – 2014-10-07 17:07:54
可能重複(http://stackoverflow.com/questions/11936327/why-am-i-receiving-illegalformatconversionexception-in-java-for-this-code) – 2014-10-07 17:10:13
爲什麼'%n'作爲最後的格式說明符? – Rustam 2014-10-07 17:11:24