找类是的数据

 

 

找类是的数据

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class One {

    static void findConnected(int[][] arr, int n, int x, int y) {

        int result = arr[x][y];

        if (y + 1 <= n && arr[x][y + 1] == result) {

            System.out.println(x + "," + y);

            arr[x][y] = 0;

//            y++;
            findConnected(arr, n, x, y+1);
        }
//        System.out.println("---------------");
//
//        System.out.println(y - 1 >=0);
//        System.out.println("---------------");

        if (y - 1 >= 0 && arr[x][y - 1] == result) {


            System.out.println(x + "," + y);

            arr[x][y] = 0;

//            y--;
            findConnected(arr, n, x, y-1);
        }

        if (x - 1 >= 0 && arr[x - 1][y] == result) {


            System.out.println(x + "," + y);

            arr[x][y] = 0;

//            x--;
            findConnected(arr, n, x-1, y);
        }
        if (x + 1 <= n && arr[x + 1][y] == result) {

            System.out.println(x + "," + y);

            arr[x][y] = 0;

//            x++;
            findConnected(arr, n, x+1, y);
        }


    }

    public static void main(String[] args) {

        int[][] temp = {
                {13, 67, 6, 3, 11},
                {13, 10, 5, 11, 8},
                {10, 10, 10, 41, 41},
                {2 , 2 , 10, 10, 33},
                {13, 10, 13, 22, 34},
        };

        findConnected(temp, temp.length, 2, 1);

        System.out.println();


        for (int i=0;i<temp.length;i++){
            for (int j=0;j<temp[i].length;j++){
                System.out.print(temp[i][j]+" ");
            }
            System.out.println();
        }
    }
}