(Coderbyte) Alphabet Soup - Solução

Have the function AlphabetSoup(str) take the str string parameter being passed and return the string with the letters in alphabetical order (ie. hello becomes ehllo). Assume numbers and punctuation symbols will not be included in the string.

Solução:

import java.util.*;
import java.io.*;

class Function { 
  String AlphabetSoup(String str) {
 
    char[] chars = str.toCharArray();
    Arrays.sort(chars);
   
    str = new String(chars);
      
    return str;
   
  }
 
  public static void main (String[] args) { 
    // keep this function call here    
    Scanner  s = new Scanner(System.in);
    Function c = new Function();
    System.out.print(c.AlphabetSoup(s.nextLine()));
  }  
 
}          

Comments

Popular posts from this blog

(Coderbyte) Powers of Two - Solução

(Coderbyte) Dash Insert II - Solução

(CoderByte) Number Search - Solução