Ask Question

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)

+1
Answers (1)
  1. 9 April, 16:51
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers