**
**
import java.util.Scanner; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); int[][] arrays = { { 0, 1, 1, 0, 0, 0, 0 }, { 1, 1, 0, 1, 0, 0, 0 }, { 1, 0, 1, 0, 0, 0, 1 }, { 0, 1, 0, 0, 0, 1, 0 } }; for (int i = 0; i < arrays.length; i++) { for (int j = 0; j < arrays[i].length; j++) { System.out.print(arrays[i][j]+" "); } System.out.println(); } int sum=1; // 循环一下代码 while(sum>0) { sum=0; System.out.println("请输入行"); int i=scanner.nextInt(); System.out.println("请输入列"); int j=scanner.nextInt(); //修改坐标 if (i-1>=0) { //上面修改 arrays[i-1][j]=1-arrays[i-1][j]; } if(i+1<arrays.length) { //修改下面 arrays[i+1][j]=1-arrays[i+1][j]; } if(j-1>=0) {//修改左边 arrays[i][j-1]=1-arrays[i][j-1]; } if(j+1<arrays[i].length) {//修改 右边 arrays[i][j+1]=1-arrays[i][j+1]; } for (int j2 = 0; j2 < arrays.length; j2++) { for (int k = 0; k < arrays[j2].length; k++) { System.out.print(arrays[j2][k] + " "); } System.out.println(); } for (int j2 = 0; j2 < arrays.length; j2++) { for (int k = 0; k < arrays[j2].length; k++) { sum+=arrays[j2][k]; } } } System.out.println("游戏结束"); } }