//从键盘接收一个字符串, 程序对其中所有字符进行排序,例如键盘输入: helloitcast程序打印:acehillostt
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println("输入字符");
String a =sc.next();
char[] arr=a.toCharArray();//转换成字符数组
TreeSet<Character> b =new TreeSet<>(new Comparator<Character>() {
@Override
public int compare(Character s1, Character s2) {
int num =s1.compareTo(s2);
return num ==0 ? 1:num;
}
});
for (char c : arr) {
b.add(c);
}
for (Character character : b) {
System.out.println(character);
}
}
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
System.out.println("输入字符");
String a =sc.next();
char[] arr=a.toCharArray();//转换成字符数组
TreeSet<Character> b =new TreeSet<>(new Comparator<Character>() {
@Override
public int compare(Character s1, Character s2) {
int num =s1.compareTo(s2);
return num ==0 ? 1:num;
}
});
for (char c : arr) {
b.add(c);
}
for (Character character : b) {
System.out.println(character);
}
}