本帖最后由 ytblght55 于 2013-6-25 21:43 编辑
- class Demo
- {
- public static void main(String[] args)
- {
- /*
- 需求:利用二维的数组打印出一个空心的菱形
- 将如下所示的数组转化为一个空心的菱形
- int map[][]={
- {0,0,0,1,0,0,0},
- {0,0,1,0,1,0,0},
- {0,1,0,0,0,1,0},
- {1,0,0,0,0,0,1},
- {0,1,0,0,0,1,0},
- {0,0,1,0,1,0,0},
- {0,0,0,1,0,0,0}
- };
- */
- int map[][]={
- {0,0,0,1,0,0,0},
- {0,0,1,0,1,0,0},
- {0,1,0,0,0,1,0},
- {1,0,0,0,0,0,1},
- {0,1,0,0,0,1,0},
- {0,0,1,0,1,0,0},
- {0,0,0,1,0,0,0}
- };
- lx(map);
- }
- //这是一个打印空心菱形的方法
- public static void lx(int arr [] [])
- {
- for (int x =0; x<arr.length ; x++)
- {
- for (int y=0;y<arr[x].length ;y++ )
- {
- if (arr[x][y]==0)
- {
- System.out.print(" ");
- }
- else
- {
- System.out.print("* ");
- }
- }
- System.out.println();
- }
- }
- }
复制代码 |