Skip to content

Commit 9efe948

Browse files
committed
Alphabet Soup
1 parent 76b49c7 commit 9efe948

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/easy/AlphabetSoup.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package easy;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* Have the function AlphabetSoup(str) take the str string parameter being passed
7+
* and return the string with the letters in alphabetical order (i.e. hello becomes ehllo).
8+
* Assume numbers and punctuation symbols will not be included in the string.
9+
*/
10+
public class AlphabetSoup {
11+
12+
/**
13+
* Alphabet Soup function.
14+
*
15+
* @param str input string
16+
* @return the string with the letters in alphabetical order
17+
*/
18+
private static String alphabetSoup(String str) {
19+
char[] letters = str.toCharArray();
20+
Arrays.sort(letters);
21+
return String.valueOf(letters);
22+
}
23+
24+
/**
25+
* Entry point.
26+
*
27+
* @param args command line arguments
28+
*/
29+
public static void main(String[] args) {
30+
var result1 = alphabetSoup("leftfield");
31+
System.out.println(result1);
32+
var result2 = alphabetSoup("underworld");
33+
System.out.println(result2);
34+
}
35+
36+
}

0 commit comments

Comments
 (0)