10、取出一个字符串中字母出现的次数。如:字符串:"abcde%^kka27qoq" ,输出格式为: a(2)b(1)k(2)...
import java.util.Scanner;
//个人认为本体主要是解决 字符排序,而输入的基本是字符。否则只能说出题者。。。
public class Hello {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String string = scanner.nextLine();
char [] chars = string.toCharArray();
char character;
int []recoder = new int[26];
for(int i = 0; i < chars.length; i++){
for(int j = i + 1; j < chars.length; j++){
if(chars[i] > chars[j]){
character = chars[i];
chars[i] = chars[j];
chars[j] = character;
}
}
}
for(int i = 0; i < 26; i++)
recoder[i] = 0;
for(int i = 0; i < chars.length; i++){
recoder[chars[i] - 'a']++;
}
for(int i = 0; i < 26; i++){
if(recoder[i] != 0){
System.out.print((char)(i+ 'a' ) + "(" + recoder[i] + ")");
}
}
System.out.println();
}
}