JAVA编程

[复制链接]
查看11 | 回复0 | 2009-11-10 12:07:43 | 显示全部楼层 |阅读模式
楼主的意思应该是计算一个句子中包含元音字母的单词所占比例吧import java.io.*;public class Demon{ public static void main(String args[]) {try{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str; String[] word;//单词数组 int count;//包含元音字母的单词个数 do {
count=0;
System.out.println("Please input the sentence:");
str=br.readLine();
word=str.split("\\s");//句子分割为单词
for(int i=0;i<word.length;i++)//遍历单词数组,查找包含元音字母的单词
{
if(word.matches("[a-zA-Z]*[aeiouAEIOU][a-zA-Z]*"))
count++;
}
System.out.println("此句中出现包含元音字母的单词所占比例为:"+((double)count/(double)word.length)*100+"%");
System.out.println("Do you want to try another? (y/n)");
str = br.readLine(); } while(str.equals("y"));}catch(IOException ex){ System.out.println("发生异常:"+ex.getMessage());} }}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行