diff --git a/Counting vowels b/Counting vowels new file mode 100644 index 0000000..3412c3f --- /dev/null +++ b/Counting vowels @@ -0,0 +1,40 @@ +/**if a string is added the program counts the number + of vowels in it**/ + + + + + +import java.util.*; + +public class CountingVowels { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + int sum = 0; + char[] vowels = {'a', 'e', 'i', 'o', 'u'}; + int[] counts = new int[5]; + + System.out.print("What word would you like to use? "); + String word = sc.nextLine().toLowerCase(); + + for (int i = 0; i < word.length(); i++) { + char current = word.charAt(i); + for (int j = 0; j < vowels.length; j++) { + if (current == vowels[j]) { + sum++; + counts[j]++; + } + } + } + + System.out.println("Total amount of vowels: " + sum); + System.out.println("Amount of As: " + counts[0]); + System.out.println("Amount of Es: " + counts[1]); + System.out.println("Amount of Is: " + counts[2]); + System.out.println("Amount of Os: " + counts[3]); + System.out.println("Amount of Us: " + counts[4]); + + } + +}