229k views
3 votes
JAVA

Write a method that returns true if a String has more than one vowel.

public static boolean containsVowels(String word){
}

1 Answer

1 vote

Answer:

Answer is in the provided screenshot!

Step-by-step explanation:

Steps required to solve this problem:

1 - define what characters are "vowels" by assigning them to an array.

2 - create a variable to record the amount of vowels there are in the string.

3 - convert the input string into a character array and iterate through each character

4 - for each of the character of the string we go through, check if it matches any of the vowels

5 - return true if the vowel count is greater than 1

Alternative methods using the Java Stream API have also been wrote, please respond if you require them.

JAVA Write a method that returns true if a String has more than one vowel. public-example-1
User Seli
by
6.3k points