统计字符出现的次数。2016-10-27

来源:互联网 发布:网络五大鬼畜歌曲 编辑:程序博客网 时间:2024/06/09 14:08
import java.util.Scanner;/** * Created by ttc on 16-10-27. */public class Test1027a{    public static void main(String[] args)    {        System.out.println("please input a string:");        Scanner sc = new Scanner(System.in);        String str = sc.nextLine();        int []word=new int[26];        for (int i = 0; i < str.length(); i++)        {            char c = str.charAt(i);            if(Character.isLetter(c))            {                word[c-'a']++;                System.out.print(c);            }        }        for(int j=0;j<26;j++)        {           //System.out.println(word[j]);            if(word[j]>0)            System.out.println((char)('a'+j)+"出现了"+word[j]+"")        }    }}
0 0