public static void main(String[] args) {
        int count = 0;
        int arr[][] = { {1, 1, 0, 0, 0},
                        {0, 1, 0, 0, 1},
                        {1, 0, 0, 1, 1},
                        {0, 0, 0, 0, 0},
                        {0, 1, 1, 0, 1}};
        boolean visited [][] = new boolean[5][5];
        for(int i =0; i < 5;i ++)
            for(int j = 0 ; j<5;j++)
                visited[i][j] = false;
        // without modifying the original array
        // uses auxillary boolean array to track which spaces have been visited
        for(int  i =0; i<5;i++){
            for(int j = 0; j<5;j++){
                if(arr[i][j] == 1 && !visited[i][j]){
                    count++;
                    countIslandsWithoutModifyingTheArray(arr,visited,i,j);
                }

            }
        }

        System.out.println("without modifying count = " + count);
        count = 0;
        // modify the original array
        for(int  i =0; i<5;i++){
            for(int j = 0; j<5;j++){
                if(arr[i][j] == 1) {
                    count++;
                    countIslandsByModifyingTheArray(arr,i,j);
                }

            }
        }

        System.out.println("after modifying count = " + count);
    }