In: Computer Science
Write a recursive method, vowels, that returns the number of vowels in a string. Also, write a program to test your method.
(JAVA Code)
import java.util.Scanner; public class Main { public static int vowels(String s) { int count = 0; s = s.toLowerCase(); for(char c: s.toCharArray()) { if("aeiou".contains(c + "")) { count++; } } return count; } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); System.out.println("Enter your sentence: "); String s = scnr.nextLine(); System.out.println("number of vowels: " + vowels(s)); scnr.close(); } }