Is there a way to clean up this recursion code?
Ok, so I wrote a program to count the number of vowels in a user inputted string.
The program works great. However, I was wondering if there was a way to clean my recursion method up, trying to get things as simple as possible if this isn't it. Need to work on cleaning my code up.
Here is the program:
Any advice is much appreciated.
//Program to test vowel count
public class VowelCount
static BufferedReader keyboard =
new BufferedReader(new InputStreamReader(System.in));
static int countVowels(String s)
if (s.length() == 0) return 0;
int tailResult = countVowels(s.substring(1));
case 'a': case 'A':
case 'e': case 'E':
case 'i': case 'I':
case 'o': case 'O':
case 'u': case 'U':
public static void main(String args) throws IOException
System.out.println("Please enter a string of letters: ");
s = keyboard.readLine();
System.out.println("The string you entered is: " + s);
System.out.println("The number of vowels in the string is: " + countVowels(s));