From 1b02233c2095dd6a17dd22b80072442f65638b61 Mon Sep 17 00:00:00 2001 From: st <31894520+ayiht@users.noreply.github.com> Date: Mon, 30 Oct 2017 07:39:08 +0530 Subject: [PATCH] Create Counting vowels --- Counting vowels | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Counting vowels 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]); + + } + +}