文字列を分割し、3つ以上の母音を含む文字列を返すプログラムを作成しようとしています。私は方法の終わりに配列を返す方法を知らない。配列外の例外を受け取り続ける
私のプログラムで、明らかに私が見ることができない問題はどこにありますか?
public class SplitWords {
public static void main(String [] args){
Scanner scan = new Scanner(System.in);
final int MIN_SIZE = 4;
int size = 0;
do{
System.out.println("How many words are you typing(min " + MIN_SIZE + "): ");
size = scan.nextInt();
}while(size < MIN_SIZE);
scan.nextLine();
String[] myarray = new String[size];
for(int i = 0; i < myarray.length; i++){
System.out.println("Type the sentence in the position " + i);
myarray[i] = scan.nextLine();
}
System.out.println("The words which have 3 or more vowels are: " + findVowels(myarray));
}
public static String findVowels(String[] myarray){
for(int i = 0; i < myarray.length; i++){
String[] tokens = myarray[i].split(" ");
int count = 0;
for(int j = 0; j < myarray.length; j++) {
if(isVowel(tokens[i].charAt(j))){
count++;
}
}
if(count > 3){
break;
}
}
return null;
}
public static boolean isVowel(char ch){
switch(ch){
case 'a':
case'e':
case'i':
case'o':
case'u':
case'y':
return true;
}
return false;
}
}
'tokens [i]' ....なぜあなたは 'tokens'に少なくとも" i + 1 "要素があると思いますか? – lurker
'if(isVowel(tokens [i] .charAt(j)))' 'tokens [i]は実際に存在すると思いますか? –