我需要编写一个关于计算给定单词中字母按字母顺序重复多少次的程序。小写字母和大写字母是相等的,它也必须适用于数字。例如:我们不得不使用数组和循环。另外,如果给定的单词/数字多于一个,它就不能计算空间,并且它还应该提示用户是否要继续。如果不是,那么他们应该输入一个点'。'或者有点时'。'之后,它应该在计算字母后关闭程序。计算给定单词中字母的频率
大学
E:1我:2 N:1 R:1秒:1 T:1 U:1个Y:1
import java.util.Scanner;
import java.lang.Character;
public class Array {
public static void main(String[] args) {
Scanner input=new Scanner (System.in);
int[] letters =new int [26];
String str= input.nextLine();
str=str.toLowerCase();
for (int i=0; i<str.length(); i++)
{
letters[i]=0;
}
System.out.println(str.length());
System.out.println(char2int('a'));
System.out.println(char2int ('D'));
}
public static int char2int (char c) {
return Character.toLowerCase(c)-(int)'a';
}
}
这出来,例如
我
你有什么问题吗? – anirudh
我试过改变代码并添加其他循环,但我不能让它看起来像我给出的例子。 – user3558676