java 每日习题(二) 用decimalFormat格式化输出
import java.text.DecimalFormat; import java.text.NumberFormat; /* * 输出: 02 A 04 A 06 A 08 A 10 A; 12 A 14 A 16 A 18 A 20 A; 22 A 24 A 26 A 28 A 30 A; 32 A 34 A 36 A 38 A 40 A; 42 A 44 A 46 A 48 A 50 A; */ public class outputPattern { public static void main(String[] args) { //decimalFormat格式化输出 DecimalFormat dfnum = (DecimalFormat)NumberFormat.getInstance(); dfnum.applyPattern("00"); for (int i = 2; i <= 50; i+=2) { if (i % 10 != 0) { System.out.print(dfnum.format(i) + " A "); } else { System.out.print(dfnum.format(i) + " A"); System.out.println(";"); } } } }