打印如下

来源:百度文库 编辑:神马文学网 时间:2024/04/30 00:56:34
用JAVA编程打印如下图所示:
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
public class Test {
public static void main(String args[]) {
for(int i = 1; i <= 7; ++i) {
for(int j = 1; j <= 7; ++j) {
int val = 4 - Math.abs(j - 4) - Math.abs(i - 4);
if(val < 1) {
System.out.print("  ");
} else {
System.out.print(val + " ");
}
}
System.out.println();
}
}
}