import java.util.Scanner;
public class CountVowel{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
获取数组的大小:
System.out.println("Type how many words will be typed: ");
int input = scan.nextInt();
用字符串值填充数组
String[] ar1 = new String[input];
for(int i = 0; i < ar1.length; i++){
System.out.println("Type the elements of array with words: ");
ar1[i] = scan.next();
}
程序的输出:
System.out.println( input + " words are typed and " +
countVowels(ar1) +
" of them contain more than 3 vowels.");
}
计算元音的方法:
public static int countVowels(String[] ar1){ // this method counts
int a = 0;
String[] ar2 = new String[]{"a", "e", "i", "u", "y", "o"};
for(int i = 0; i < ar1.length; i++){
for(String s : ar2){
if(ar1[i].toLowerCase().contains(s)){
a++;
}
}
}
return a;
}
}
上面的方法是检查元音,但我不知道如何让它检查是否有超过3个元音。
狐的传说
梵蒂冈之花
肥皂起泡泡
慕标5832272
Smart猫小萌
相关分类