Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA Write a recursive method called noVowels that takes a String as an argument

ID: 3763472 • Letter: J

Question

JAVA

Write a recursive method called noVowels that takes a String as an argument and returns true if the String does not contain any 'a', 'e', 'i', 'o', or 'u' characters, false if it contains at least one of these characters.  Identify your base case and your general case. You may assume that the input String will never be allowed to be null. Use the following method signature:

HINT: You will want to use the substr method to make your problem a little smaller. Think about how you can break this problem up into smaller problems.

Explanation / Answer

public static boolean noVowels(String str){
   if(str == NULL)
       return true;
   if(str.charAt(0) == 'a' || str.charAt(0) == 'e' || str.charAt(0) == 'i' || str.charAt(0) == 'o' ||str.charAt(0) == 'u')
       return noVowels(str.substr(1));
   else
       return false;
}