import java.util.Arrays;
/**
*
* @author LYWZL
*1.从键盘获得一串字符
*2.把获得的这一串字符转换成字符数组
*3.把相同的字符统计成个数
* 3.1把字符数组进行排序,一个字符对应的是一个整数值。
* 3.2统计出相同字符的个数
* 3.3打印输出
* */
import java.util.Scanner;
public class CountChar {
public static void main(String[] args) {
// 从键盘获得一行字符 nextLine()
System.out.println("请输入一串字符");
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
// 把获得的字符串转换成字符数组
char[] ch = str.toCharArray();
// 给这个数组进行排序
Arrays.sort(ch);
// 把相同的字符统计出个数
int count = 0;
for (int i = 0; i < ch.length;) {
count = 0;
for (int j = i; j < ch.length; j++) {
if (ch[i] == ch[j]) {
count++;
}
}
// 打印输出
if (count > 0) {
System.out.println(ch[i] + ":" + count);
i += (count);
}
}
}
}