Simplify CheckVowels (#3172)
This commit is contained in:
parent
6665ab262c
commit
b0f21803d1
@ -19,24 +19,15 @@ public class CheckVowels {
|
|||||||
* @return {@code true} if given string has vowels, otherwise {@code false}
|
* @return {@code true} if given string has vowels, otherwise {@code false}
|
||||||
*/
|
*/
|
||||||
public static boolean hasVowels(String input) {
|
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) {
|
if (input == null) {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
int cnt = 0;
|
input = input.toLowerCase();
|
||||||
for (char c : input.toLowerCase().toCharArray()) {
|
for (int i = 0; i < input.length(); i++) {
|
||||||
if (VOWELS.contains(c)) {
|
if (VOWELS.contains(input.charAt(i))) {
|
||||||
++cnt;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cnt;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user