
一道JAVA作业题 求解答啊!
3个回答
展开全部
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入英文字符:");
String temp = sc.next();
temp = temp.toUpperCase();//全部大写
int[] English = new int[26];
for (int i = 0; i < temp.length(); i++)
{
English[temp.charAt(i)-65]++;//A对应0
}
for (int i = 0; i < English.length; i++)
{
System.out.println((char)(i + 65) + "出现的次数为:" + English[i]);
}
}
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入英文字符:");
String temp = sc.next();
temp = temp.toUpperCase();//全部大写
int[] English = new int[26];
for (int i = 0; i < temp.length(); i++)
{
English[temp.charAt(i)-65]++;//A对应0
}
for (int i = 0; i < English.length; i++)
{
System.out.println((char)(i + 65) + "出现的次数为:" + English[i]);
}
}
展开全部
Scanner scan = new Scanner(System.in);
System.out.println("请输入英文字符串:");
String str = scan.nextLine();
char src[] = str.toLowerCase().toCharArray();
char ch[] = new char[128];
for(int i = 0; i < src.length; i++)
ch[(int)src[i]]++;
for(int i = 0; i < ch.length; i++)
if(ch[i] > 0)
System.out.println((char)i + "出现了 " + (int)ch[i] + " 次");
System.out.println("请输入英文字符串:");
String str = scan.nextLine();
char src[] = str.toLowerCase().toCharArray();
char ch[] = new char[128];
for(int i = 0; i < src.length; i++)
ch[(int)src[i]]++;
for(int i = 0; i < ch.length; i++)
if(ch[i] > 0)
System.out.println((char)i + "出现了 " + (int)ch[i] + " 次");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Test {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String line = in.nextLine();
in.close();
Map<String, Integer> map = new HashMap<String, Integer>();
for (int i=0;i<line.length();i++) {
String str = String.valueOf(line.charAt(i)).toLowerCase();
if (map.get(str) == null) {
map.put(str, 1);
} else {
map.put(str, map.get(str) + 1);
}
}
for (String s : map.keySet()) {
System.out.println(s + "出现" + map.get(s) + "次");
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |