java高级练习字母出现多少次

来源:互联网 发布:淘宝退款原因质量问题 编辑:程序博客网 时间:2024/06/15 04:41
package com.company;import java.util.Scanner;/** * Created by ttc on 16-10-27. */public class 练习{    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 j = 0;j<26;j++)//        {//            System.out.print(word[j]);//        }//            System.out.println("");        for(int i=0;i<str.length();i++)        {            char c = str.charAt(i);            if(Character.isLetter(c))            {                int num = word[c - 'a'];                num++;                word[c - 'a'] = num;            }        }        for(int j = 0;j<26;j++)        {            if(word[j]>0)                System.out.println((char)('a'+j)+"出现了"+word[j]+"次");        }    }}

1 0
原创粉丝点击