高分悬赏! 哪位java的高手进来帮我编程啊,十分感谢!

输入一字符串,删除其中单词中的元音字母,保留的单个元音字母,将两个连续相同的非元音字母去除一个,将结果输出,并计算单词数和平均每个单词删除的字数
就是说如果输进一个元音字母是不变的,比如输进a,出来的还是a,不能把它删掉了,可以帮我修改一下吗??谢谢!

这样就行:
import java.io.*;
public class Demon
{
public static void main(String args[])
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str="";
String sen="";//英文句子
String[] word;
int count;
double percent;
while(str.matches("[nN]")==false)
{
System.out.println("Please enter a Sentence");
sen=br.readLine();
count=sen.length();//记录句子的原长
word=sen.split("\\s");//分割句子为单词数组
sen="";
for(String temp : word) //去除元音字母和重复字符
{
temp=temp.replaceAll("[aeiou]","");
temp=temp.replaceAll("(?s)(.)(?=.?\\1)", "");
sen+=temp+" ";
}
percent=(double)(count-sen.length()+1)/(double)word.length;//计算平均每个单词删除的字数
System.out.println("Abbreviated String:"+sen);
System.out.println("Sentence Stats");
System.out.println("Number of Words:"+word.length);
System.out.println("Average number of letters dropped per word:"+percent);
System.out.println("Do you want to try another? (y/n)");
str = br.readLine();
}
}
catch(IOException ex)
{
System.out.println("发生异常:"+ex.getMessage());
}
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-11-09
写不怎么明白 而且 什么是元音字母?
相似回答
大家正在搜