Question: how do I modify this java code so it doesn't show the permetations that contain the same letter for example so aa is not allowed

how do I modify this java code so it doesn't show the permetations that contain the same letter for example so "aa" is not allowed since "a" was already used.

class problem2 {

static int count = 1;

// The method that prints all

// possible strings of length k.

// It is mainly a wrapper over

// recursive function printAllKLengthRec()

static void printAllKLength(char[] set, int k) {

int n = set.length;

printAllKLengthRec(set, "", n, k);

}

// The main recursive method

// to print all possible

// strings of length k

static void printAllKLengthRec(char[] set, String prefix, int n, int k) {

// Base case: k is 0,

// print prefix

if (k == 0) {

System.out.println( count+ ": "+prefix);

count++;

return;

}

// One by one add all characters

// from set and recursively

// call for k equals to k-1

for (int i = 0; i

// Next character of input added

String newPrefix = prefix + set[i];

// k is decreased, because

// we have added a new character

printAllKLengthRec(set, newPrefix, n, k - 1);

}

}

// Driver Code

public static void main(String[] args) {

System.out.println("First Test");

char[] set1 = { 'a', 'b', 'c','d','e','f','g','h','i' };

int k = 2;

printAllKLength(set1, k);

}

}

how do I modify this java code so it doesn't show the

abcd tabcdefghbbbh 0123 F-234567891111

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!