平面图形问题都可以采用二维数组的方式解决
public static void main(String[] args) {
int arr[][] = new int[3][9];
int x = 2;
int m = 0;
boolean sign = false;
for (int y = 1; y <= 9; y++) {
arr[x][m] = y;
m++;
if (!sign)
x--;
if (sign)
x++;
if (x < 0) {
sign = true;
x = x + 2;
}
if (x > 2) {
sign = 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();
}
}
}