import java.io.*;
import java.util.*;
public class text
{
public text()throws IOException
{
InputStreamReader reader=new InputStreamReader(System.in);
BufferedReader input=new BufferedReader(reader);
System.out.println("\n请输入字符串:");
String s=input.readLine();
System.out.println("\n统计各元音出现次数:");
count1(s);
System.out.println("\n统计各单词长度:");
count2(s);
}
void count1(String s)
{
int i=0,ca=0,ce=0,ci=0,co=0,cu=0;
while(i<s.length())
{
switch(s.charAt(i))
{
case 'a':ca++;break;
case 'e':ce++;break;
case 'i':ci++;break;
case 'o':co++;break;
case 'u':cu++;break;
default :break;
}
i++;
}
System.out.println("a:"+ca+"\ne:"+ce+"\ni:"+ci+"\no:"+co+"\nu:"+cu);
}
private int j=0;
char count2(String s)
{
StringBuffer str=new StringBuffer();
while(j<s.length())
{
if((s.charAt(j)>='a'&&s.charAt(j)<='z')||(s.charAt(j)>='A'&&s.charAt(j)<='Z'))
{
str.append(s.charAt(j));
j++;
}
else
{
if(str.toString().length()>0)
System.out.println(str.toString()+":"+str.toString().length());
j++;
return count2(s);
}
}
return 0;
}
public static void main(String[]args)throws IOException
{
text mytext=new text();
}
}
温馨提示:答案为网友推荐,仅供参考