Ask Question
20 January, 14:57

You will be given a string, containing both uppercase and lowercase alphabets (numbers are not allowed).

You have to print all permutations of string with the added constraint that you can't change the uppercase alphabets positions.

Example: (puNeeTgUlia)

+2
Answers (1)
  1. 20 January, 18:15
    0
    The Java code is given below with appropriate comments

    Explanation:

    import java. util.*;

    class Main {

    static Set set = new HashSet ();

    static void printPerms (char ch[], int ind) {

    //If end of string is reached, add it to set

    if (ind==ch. length) {

    set. add (new String (ch));

    return;

    }

    for (int i=ind; i
    //Only swap if lower case

    if ((ch[i]>='a' && ch[i]='a' && ch[ind]<='z'))) {

    char t = ch[i];

    ch[i] = ch[ind];

    ch[ind] = t;

    }

    printPerms (ch, ind+1);

    if ((ch[i]>='a' && ch[i]='a' && ch[ind]<='z'))) {

    char t = ch[i];

    ch[i] = ch[ind];

    ch[ind] = t;

    }

    }

    }

    public static void main (String[] args) {

    printPerms ("aBbCc". toCharArray (),0);

    System. out. println (set);

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “You will be given a string, containing both uppercase and lowercase alphabets (numbers are not allowed). You have to print all permutations ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers