アリZekaj:
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つの以上の母音がある場合、それはチェック作る方法を知りません。
アラン:
public static int countVowels(String[] ar1) { // this method counts
int vowelPerWord = 0;
int totalWordsWithThreeVowels = 0;
char[] ar2 = new char[] { 'a', 'e', 'i', 'u', 'y', 'o' };
for (int i = 0; i < ar1.length; i++) {
vowelPerWord = 0;
for (int j = 0; j < ar1[i].length(); j++) {
for (int k = 0; k < ar2.length; k++) {
if (ar2[k] == (ar1[i].charAt(j))) {
vowelPerWord++;
}
}
}
if (vowelPerWord >= 3) {
totalWordsWithThreeVowels++;
}
}
return totalWordsWithThreeVowels;
}
EDIT
大丈夫、今私は、エラーを修正し、少しより多くの意味を作るためにvariablenames編集しました。これはOであるが、(N * M)私は信じては(あまり良くない複雑さ)、それはこの場合にはAR1を仕事を取得するあなたの入力である(ここで、n文字列とMのammountが最も長い文字列が持つ文字のammountです)文字列は、AR2は存在だけで母音です。
あなたが0にAR1とセット「vowelPerWord」内のすべての文字列を通過するので、それはあなたがその文字列のすべての文字を経た後に母音が、最後に1ずつvowelPerWordを高めている場合、すべての文字列内のすべての単一のcharを通過し、確認してください3つの以上の母音があった場合はその終了時に返却されtotalWordsWithThreeVowelsを、増やす場合は、確認してください。