您的位置:首页 > 编程语言 > Java开发

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

2016-10-27 16:55 176 查看
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]+"次");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: