方法,好像在程序計算串的數量在ArrayList中,而不是數起,但元音編寫一個名爲averageVowels
import java.util.*;
public class AverageVowels {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("Tooo");
list.add("beee");
list.add("ooor");
list.add("nooot");
list.add("Toooo");
list.add("beeee");
averageVowels(list);
}
public static double averageVowels(ArrayList<String> list) {
double count = 0;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).contains("a")
|| list.get(i).contains("e")
|| list.get(i).contains("i")
|| list.get(i).contains("o")
|| list.get(i).contains("u")) {}
count++;
}
double average = (double) list.size()/count;
System.out.println(average);
return average;
}
}
人物
即使循環是正確的,它也沒有正確計算平均值。 –