将一个随机字符串中的所有字符升序排列,并倒序打印
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("随机输入字符串:");
String s = sc.next();
sort(s);
}
public static void sort(String s) {
char [] c = s.toCharArray() ;
Arrays.sort(c);
System.out.println("升序排序:");
for(char e : c) {
System.out.print(e+" ");
}
System.out.println();
System.out.println("输入字符串倒序排列为:");
for (int i = c.length - 1; i >= 0; i--) {
System.out.print(c[i] + " ");
}
}
}