Formatted with Google Java Formatter

This commit is contained in:
github-actions
2021-09-22 16:29:51 +00:00
parent 2e586b7b3c
commit ce151a8bd8

View File

@ -1,48 +1,51 @@
package strings; package strings;
/** /**
* Vowel Count is a system whereby character strings are placed in order based on the * Vowel Count is a system whereby character strings are placed in order based on the position of
* position of the characters in the conventional ordering of an alphabet. Wikipedia: * the characters in the conventional ordering of an alphabet. Wikipedia:
* https://en.wikipedia.org/wiki/Alphabetical_order * https://en.wikipedia.org/wiki/Alphabetical_order
*/ */
class CheckVowels{ class CheckVowels {
public static void main(String[] args) { public static void main(String[] args) {
assert !hasVowels("This is a strings"); assert !hasVowels("This is a strings");
assert hasVowels("Hello World"); assert hasVowels("Hello World");
assert hasVowels("Java is fun"); assert hasVowels("Java is fun");
assert !hasVowels("123hi"); assert !hasVowels("123hi");
assert hasVowels("Coding vs Programming"); assert hasVowels("Coding vs Programming");
} }
/** /**
* Check if a string is has vowels or not * Check if a string is has vowels or not
* *
* @param input a string * @param input a string
* @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) {
if(input.matches("[AEIOUaeiou]")){ if (input.matches("[AEIOUaeiou]")) {
countVowels(input); countVowels(input);
return true; return true;
}
return false;
} }
/** return false;
* count the number of vowels }
* /**
* @param input a string * count the number of vowels
* prints the count of vowels *
*/ * @param input a string prints the count of vowels
public static void countVowels(String input){ */
input.toLowerCase(); public static void countVowels(String input) {
int count=0; input.toLowerCase();
int i=0; int count = 0;
while(i<input.length()){ int i = 0;
if(input.charAt(i)=='a' || input.charAt(i)=='e'||input.charAt(i)=='i'||input.charAt(i)=='o'||input.charAt(i)=='u' ){ while (i < input.length()) {
count++; if (input.charAt(i) == 'a'
} || input.charAt(i) == 'e'
i++; || input.charAt(i) == 'i'
} || input.charAt(i) == 'o'
System.out.println(count); || input.charAt(i) == 'u') {
count++;
}
i++;
} }
} System.out.println(count);
}
}