public class Test { private static String formatData(final int len, final String data) { return String.format("%"+len+"s",data); } public static void main(String... args) { final int MAX = 10; final int LEN = Integer.toString(MAX).length()*2 + 2 + Integer.toString(MAX*MAX).length(); for (int r = 1; r <= MAX; r++) { for (int s = MAX - r + 1; s < MAX; s++) { System.out.print(formatData(LEN,"\t")); } for (int c = r; c <= MAX; c++) { final String sData = String.format("%d*%d=%d", r, c, (r * c)); System.out.print(formatData(LEN,sData)); System.out.print((c == MAX) ? '\n' : '\t'); } } } }
[此贴子已经被作者于2017-12-21 17:12编辑过]