本帖最后由 zaoyangkun 于 2016-6-12 20:34 编辑
package com.heima.text; public class NewClass { public static void main(String[] args) {
int sum;
for (int i = 1; i <= 9; i++) {
for (int m = i; m <= 9; m++) { //增加一个for循环,输出补位空格
System.out.format("%15s", ""); //打印一次相当于一个式子的空间位置
}
for (int j = 1; j <= i; j++) {
sum = i * j;
System.out.format("%10s", j + "*" + i + "=" + sum + " "); //格式化输出,让结果更整齐
}
System.out.println();
}
}
}
|