The problem
Write a method that returns a sorted string using the following header: public static String sort(String s)
. For example, sort("acb") returns abc. Write a test program that prompts the user to enter a string and displays the sorted string.
Breaking it down
public static void main(String[] args) {
System.out.print("Enter a string: ");
Scanner input = new Scanner(System.in);
String s = input.next();
input.close();
Stream.of(s.split("")).sorted().forEach(System.out::println);
}
Output
Enter a string: acb
a
b
c