思路:市容nextLine();吸收数据,逐个使用charAt来判断元音的数量并记录即可。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner a=new Scanner(System.in);
while(a.hasNext())
{
int n=a.nextInt();
int q=0,e=0,r=0,o=0,u=0;
a.nextLine(); //吸收空格键,不然无法正常输入
for(int i=0;i<n;i++)
{
q=0;e=0;r=0;o=0;u=0;
String str=a.nextLine(); //不忽略空格输入
for(int j=0;j<str.length();j++) //逐个筛选
{
if(str.charAt(j)=='a')
q++;
else if(str.charAt(j)=='e')
e++;
else if(str.charAt(j)=='i')
r++;
else if(str.charAt(j)=='o')
o++;
else if(str.charAt(j)=='u')
u++;
}
System.out.println("a:"+q);
System.out.println("e:"+e);
System.out.println("i:"+r);
System.out.println("o:"+o);
System.out.println("u:"+u);
if(i<(n-1)) //注意格式,在最后加空行
System.out.println();
}
}
}
}
若有错误,还请指正。