package jdbcdemotest;
import java.util.Scanner;
/**计算某字符串中某个字母出现的次数
* Created by Administrator on 2016/10/27 0027.
*/
public class JdbcDemo1
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("请写出一串字母:");
String str=sc.nextLine();
int[] word=new int[26];
for(int i=0;i<str.length();i++)
{
char ch=str.charAt(i);
if(Character.isLetter(ch))
{
word[ch-'a']++;
}
}
for(int j=0;j<word.length;j++)
{
if(word[j]>0)
{
System.out.println((char)(j+'a')+"出现了"+word[j]+"次");
}
}
}
}
计算某字符串中某个字母出现的次数
最新推荐文章于 2024-01-30 08:58:01 发布