From b0f21803d1b9ec67ef573156db43741f19226d34 Mon Sep 17 00:00:00 2001 From: Arthita Paul <71807177+Arthita@users.noreply.github.com> Date: Fri, 1 Jul 2022 17:28:28 +0530 Subject: [PATCH] Simplify CheckVowels (#3172) --- .../thealgorithms/strings/CheckVowels.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/thealgorithms/strings/CheckVowels.java b/src/main/java/com/thealgorithms/strings/CheckVowels.java index a683a5065..af95f5945 100644 --- a/src/main/java/com/thealgorithms/strings/CheckVowels.java +++ b/src/main/java/com/thealgorithms/strings/CheckVowels.java @@ -19,24 +19,15 @@ public class CheckVowels { * @return {@code true} if given string has vowels, otherwise {@code false} */ public static boolean hasVowels(String input) { - return countVowels(input) > 0; - } - - /** - * count the number of vowels - * - * @param input a string prints the count of vowels - */ - public static int countVowels(String input) { if (input == null) { - return 0; + return false; } - int cnt = 0; - for (char c : input.toLowerCase().toCharArray()) { - if (VOWELS.contains(c)) { - ++cnt; + input = input.toLowerCase(); + for (int i = 0; i < input.length(); i++) { + if (VOWELS.contains(input.charAt(i))) { + return true; } } - return cnt; + return false; } }