-3

I want to sort the String s = "eBaDcAfg153E" Such that the sorted string contains All lowercase first and then uppercase letters and then numbers.

The output should be like s = "acefgABDE135"

Can anyone help me with that?

Thanks

BK_R
  • 3
  • 2
  • There is no place for this!, do you want write for you!? – AmirNorouzpour Sep 24 '18 at 15:12
  • What have you tried already? What specifically do you need help with? – Carcigenicate Sep 24 '18 at 15:13
  • In which programming language ? Please add it to question tags – oguz ismail Sep 24 '18 at 15:13
  • The SO community expects questioners to show at least a minimal effort to solve problems. Hence, I'd like to advise you to show what you have done so far (i.e. show your code) and where it failed. Having said this, this task could be easily accomplished if performance does not matter, or it could be complicated if you'd like to save every CPU cycle possible. A good starting point would be reading about sorting algorithms (quicksort, bubblesort and so on). – Binarus Sep 24 '18 at 15:17
  • Hi @BR_K, [Hint](https://stackoverflow.com/a/13150786/5813861) for you. this way you can solve your program. – yash Sep 24 '18 at 15:36

1 Answers1

0

Welcome to stackoverflow!

Read how to ask good question, First try to solve, and if fail then first search over Google. and if you don't find answer, then you may ask.

This solution may work for you (just for test).. Still you can improve it a lot.. Use StringBuilder for string modification.

public static void main (String[] args) throws java.lang.Exception
        {
            String inputString = "eBaDcAfg153E";
            String lowerCase = "";
            String upperCase = "";
            String numberCase = "";

            for (int i = 0; i < inputString.length(); i++) {
               char c = inputString.charAt(i);
               if(Character.isUpperCase(c)) {
                   upperCase += c;
               }else if (Character.isLowerCase(c)) {
                   lowerCase += c;
               }else if(Character.isDigit(c)) {
                   numberCase += c;
               }

            }
            char upperArray[] = upperCase.toCharArray(); 
            char lowerArray[] = lowerCase.toCharArray(); 
            char numArray[] = numberCase.toCharArray(); 

            Arrays.sort(upperArray);
            Arrays.sort(lowerArray);
            Arrays.sort(numArray);

            System.out.println(new String(lowerArray)+""+new String(upperArray)+""+new String(numArray));
        }
yash
  • 2,101
  • 2
  • 23
  • 32