Hamzah khammash
Hamzah khammash

Reputation: 238

Converting form lowercase to uppercase?

How can I convert a string from a lowercase to uppercase with all possible outputs?

For example, I have the string 'abc'; it must give all possible outputs in uppercase to show this set of strings as output:

'abC','aBc,'aBC','Abc'ABc','AbC','ABC' 

Upvotes: 0

Views: 2851

Answers (2)

Matthias Bruns
Matthias Bruns

Reputation: 900

Convert your String to an arrays String.toArray() and loop through it!
I think it's homework, so I won't give you the complete answer.

Have a look at the links: String.toLowerCase() and String.toUpperCase().

Upvotes: 3

amit modi
amit modi

Reputation: 1108

Here is the algorithm to do this:

 String input = "abc";
 int length = input.length();
 for (int i = 1;i < 2^input.length();i++){
     String bitString = convert value of i into bits (eg, 1 = 001 , 2 = 010)
     //Iterate through length of bitString
     StringBuffer newString = "";
     for (int j = 1;j < bitString.length();j++){
        if(bitString.charAt(j)=='1'){
           newString.append(convertToUpperCase(input.charAt(j));
        }else{
           newString.append(input.charAt(j));
        }
     }
     print newString
 }

Upvotes: 1

Related Questions