import java.util.Scanner;
import java.util.TreeMap;

//输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
public class Test {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入一行字符:");
		String s = sc.nextLine();
		char[] c = s.toCharArray();
		TreeMap<Character, Integer> tm = new TreeMap<>();
		for (char d : c) {
			if (!tm.containsKey(d)) {
				tm.put(d, 1);
			} else {
				tm.put(d, tm.get(d) + 1);
			}
		}
		for (Character ca : tm.keySet()) {
			System.out.println(ca + "(" + tm.get(ca) + ")");
		}
	}

}

 

相关文章:

  • 2022-12-23
  • 2021-08-04
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-02
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案