package cn.itcast.test;
public class Test4 {
public static void main(String[] args) {
/*
3 7
2 4 6 8
1 5 9
*/
int num = 23;
int height = num / 4 + 1;
int width = num;
int [][]arr = new int[height][width];
int x = height - 1;
int y = 0;
boolean order = false;
for(int i = 1; i <= num; i++){
arr[x][y] = i;
y++;
if(!order){
x--;
}
if(order){
x++;
}
if(x < 0){
order = true;
x = x + 2;
}
if(x > height -1){
order = false;
x = x - 2;
}
}
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < arr[i].length; j++){
if(arr[i][j] == 0){
System.out.print(" ");
}else{
System.out.print(arr[i][j]);
}
}
System.out.println();
}
}
}
打印平面图形(M形)
最新推荐文章于 2021-10-11 11:58:38 发布