Guest User

Untitled

a guest
Jun 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1.  
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6.  
  7. public class averageVowels {
  8.  
  9. public static void main(String[] args) {
  10. ArrayList<String> allwords = new ArrayList<String>();
  11.  
  12. Scanner input;
  13. try {
  14. input = new Scanner(new File("vowels.txt"));
  15.  
  16. while (input.hasNext()) {
  17. String word = input.next();
  18. allwords.add(word);
  19. }
  20.  
  21. averageVowels1(allwords);
  22.  
  23. } catch (FileNotFoundException e) {
  24. e.printStackTrace();
  25. }
  26. }
  27.  
  28. public static void averageVowels1(ArrayList<String> list) {
  29. double countVowels = 0;
  30. for (int i = 0; i < list.size(); i++) {
  31. String word = list.get(i);
  32. if (word.contains("a")) {
  33. countVowels++;
  34. }
  35. if (word.contains("e")) {
  36. countVowels++;
  37. }
  38. if (word.contains("i")) {
  39. countVowels++;
  40. }
  41. if (word.contains("o")) {
  42. countVowels++;
  43. }
  44. if (word.contains("u")) {
  45. countVowels++;
  46. }
  47.  
  48. }
  49. System.out.println(countVowels);
  50. }
  51. }
Add Comment
Please, Sign In to add comment