题目内容:
从键盘输入一行中英文混合的文字,统计其中出现的每个英文字母的频率并依字母表顺序,依次输出统计结果,统计时忽略字母大小写的区别。
输入格式:
一行中英文混合的文字
输出格式:
输出每个字母及其出现次数,字母之间用2个空格分隔。
输入样例:
我们学习Java,we work very hard!
输出样例:
a=3 d=1 e=2 h=1 j=1 k=1 o=1 r=3 v=2 w=2 y=1
时间限制:500ms内存限制:32000kb
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner reader = new Scanner(System.in);
String s = reader.nextLine();
s = s.toLowerCase();
char[] Lowstr;
Lowstr=s.toCharArray();
int[] a;
a=new int [25];
char[] t;
t="abcdefghijklmnopqrstuvwxy".toCharArray();
int m=t.length;
int n=s.length();
for(int i=0;i<n;i++) {
for(int j=0;j<m;j++) {
if(Lowstr[i]==t[j])
a[j]++;
}
}
for(int j=0;j<m;j++) {
if(a[j]!=0)
System.out.print(t[j]+"="+a[j]+" ");
}
}
}