java">/*
* 3 7
* 2 4 6 8
* 1 5 9
* 这类图形都可用2维数组
*/
public class PrintM {
public static void main(String[] args) {
int a[][] = new int[3][9];
a[2][0] = 1;
a[1][1] = 2;
a[0][2] = 3;
a[1][3] = 4;
a[2][4] = 5;
a[1][5] = 6;
a[0][6] = 7;
a[1][7] = 8;
a[2][8] = 9;
for(int i=0; i<3; i++){
for(int j = 0; j<9; j++){
if(a[i][j]==0){
System.out.print(" ");
}else{
System.out.print(a[i][j]);
}
}
System.out.println("");
}
}
}
如果数字多的话,可以用for循环进行输入,