Skip to content

Commit b0f2180

Browse files
authored
Simplify CheckVowels (TheAlgorithms#3172)
1 parent 6665ab2 commit b0f2180

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/main/java/com/thealgorithms/strings/CheckVowels.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,15 @@ public class CheckVowels {
1919
* @return {@code true} if given string has vowels, otherwise {@code false}
2020
*/
2121
public static boolean hasVowels(String input) {
22-
return countVowels(input) > 0;
23-
}
24-
25-
/**
26-
* count the number of vowels
27-
*
28-
* @param input a string prints the count of vowels
29-
*/
30-
public static int countVowels(String input) {
3122
if (input == null) {
32-
return 0;
23+
return false;
3324
}
34-
int cnt = 0;
35-
for (char c : input.toLowerCase().toCharArray()) {
36-
if (VOWELS.contains(c)) {
37-
++cnt;
25+
input = input.toLowerCase();
26+
for (int i = 0; i < input.length(); i++) {
27+
if (VOWELS.contains(input.charAt(i))) {
28+
return true;
3829
}
3930
}
40-
return cnt;
31+
return false;
4132
}
4233
}

0 commit comments

Comments
 (0)