0

I have written a code to do get combination of string array as below

static void printCombination(String arr[], int n, int r)
    {
        // A temporary array to store all combination one by one
        String data[]=new String[r];

        // Print all combination using temprary array 'data[]'
        combinationUtil(arr, data, 0, n-1, 0, r);
    }

    static void combinationUtil(String arr[], String data[], int start,
            int end, int index, int r)
    {
        // Current combination is ready to be printed, print it
        if (index == r)
        {
            for (int j=0; j<r; j++)
                System.out.print(data[j]+" ");
            System.out.println("");


            return;
        }

// replace index with all possible elements. The condition
// "end-i+1 >= r-index" makes sure that including one element
// at index will make a combination with remaining elements
// at remaining positions
        for (int i=start; i<=end && end-i+1 >= r-index; i++)
        {
            data[index] = arr[i];
            combinationUtil(arr, data, i+1, end, index+1, r);
        }
    }

and calling the function from main as below

int r = 2;
            int n = arrayOfPatches.length;
            printCombination(arrayOfPatches, n, r);

so now while doing the combination it is storing the data in a single array as below ABCD PQRS ABCD XYZ PQRS XYZ

so now i need to put in a 2d array so i should read it .So please help me how can i convert into 2D array in java

Mahendra Gunawardena
  • 1,956
  • 5
  • 26
  • 45
vinod
  • 87
  • 8

0 Answers0