二维数组上下左右走动
for(int i = 0 ; i < n*m ; i++) { //下 while(x + 1 < m && bj[x + 1][y] == 2) { System.out.print(arr[++x][y]); bj[x][y] = 1; } //右 while(y + 1 < m && bj[x][y + 1] == 2) { System.out.print(arr[x][++y]); bj[x][y] = 1; } //上 while(x - 1 >= 0 && bj[x - 1][y] == 2) { System.out.print(arr[--x][y]); bj[x][y] = 1; } ///左 while(y - 1 >= 0 && bj[x][y - 1] == 2) { System.out.print(arr[x][--y]); bj[x][y] = 1; } }