Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class averageVowels {
- public static void main(String[] args) {
- ArrayList<String> allwords = new ArrayList<String>();
- Scanner input;
- try {
- input = new Scanner(new File("vowels.txt"));
- while (input.hasNext()) {
- String word = input.next();
- allwords.add(word);
- }
- averageVowels1(allwords);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- public static void averageVowels1(ArrayList<String> list) {
- double countVowels = 0;
- for (int i = 0; i < list.size(); i++) {
- String word = list.get(i);
- if (word.contains("a")) {
- countVowels++;
- }
- if (word.contains("e")) {
- countVowels++;
- }
- if (word.contains("i")) {
- countVowels++;
- }
- if (word.contains("o")) {
- countVowels++;
- }
- if (word.contains("u")) {
- countVowels++;
- }
- }
- System.out.println(countVowels);
- }
- }
Add Comment
Please, Sign In to add comment