直接贴代码:
public class Test {
public static void main(String[] args) {
int num = 9;
//打印num层
for (int i = num - 1; i >= 0; i--) {
//打印左边空格
for (int j = 0;j < num-i;j++){
System.out.print(" ");
}
//倒序打印数字
for (int t = i+1;t > 0;t--){
System.out.print(t+" ");
}
//打印右边空格
for (int n = 1; n < num-i; n++) {
System.out.print(" ");
}
//换行
System.out.println();
}
}
}
打印结果: