From 2e586b7b3c637a7e48e710b42e6ea92221c23037 Mon Sep 17 00:00:00 2001 From: Shravana Tirtha <34398606+shravanatirtha@users.noreply.github.com> Date: Wed, 22 Sep 2021 21:59:16 +0530 Subject: [PATCH] Add check vowels algorithm (#2314) --- strings/CheckVowels.java | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 strings/CheckVowels.java diff --git a/strings/CheckVowels.java b/strings/CheckVowels.java new file mode 100644 index 00000000..81b25406 --- /dev/null +++ b/strings/CheckVowels.java @@ -0,0 +1,48 @@ +package strings; + +/** + * Vowel Count is a system whereby character strings are placed in order based on the + * position of the characters in the conventional ordering of an alphabet. Wikipedia: + * https://en.wikipedia.org/wiki/Alphabetical_order + */ +class CheckVowels{ + public static void main(String[] args) { + assert !hasVowels("This is a strings"); + assert hasVowels("Hello World"); + assert hasVowels("Java is fun"); + assert !hasVowels("123hi"); + assert hasVowels("Coding vs Programming"); + } + + /** + * Check if a string is has vowels or not + * + * @param input a string + * @return {@code true} if given string has vowels, otherwise {@code false} + */ + public static boolean hasVowels(String input){ + if(input.matches("[AEIOUaeiou]")){ + countVowels(input); + return true; + } + return false; + } + /** + * count the number of vowels + * + * @param input a string + * prints the count of vowels + */ + public static void countVowels(String input){ + input.toLowerCase(); + int count=0; + int i=0; + while(i