题目描述
给出一个仅包含字母的字符串,不包含空格,统计字符串中各个字母(区分大小写)出现的次数
 并按照字母出现次数从大到小的顺序。输出各个字母及其出现次数。
 如果次数相同,按照自然顺序进行排序,且小写字母在大写字母之前,
输入描述
输入一行,为一个仅包含字母的字符串,
输出描述
按照字母出现次数从大到小的顺序输出各个字母和字母次数,用英文分号分隔,注意未尾的分号;
 字母和次数间用英文冒号分隔。

//xyxyXX
//aaaaAAAAbbbbcccckkk
public class 字符统计及重排 {
    public static void main(String[] args) {
        System.out.println("请输入需要字符统计及重排的字符串:");
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        characterStatisticsAndSort(s);
    }
    private static void characterStatisticsAndSort(String s) {
        HashMap<Character, Integer> tp = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            Character c = s.charAt(i);
            tp.put(c,tp.getOrDefault(c,0)+1);
        }
        tp.entrySet().stream().sorted((o1,o2)-> {
                if (o1.getValue() != o2.getValue()){
                    return o2.getValue() - o1.getValue();
                }else if (Character.isUpperCase(o2.getKey()) && Character.isLowerCase(o1.getKey())){
                    return -1;
                }else {
                    return 1;
                }
        }).forEach(str -> System.out.print(str.getKey() + ":" + str.getValue() + ";"));
    }
}


















