How do you count the vowels in Java using Recursion ?
This programs counts the vowels present in the given string using the recurions.
Program to count the vowels using Recurions:
public static void main(String[] args){
String str = "NgDevelOper.com";
System.out.println(countVowels(str, str.length()));
}
private static int countVowels(String str, int length) {
if(length ==1){
if (isVowel(str.charAt(length-1))) {
return 1;
}else {
return 0;
}
}
return (countVowels(str, length-1)) + (isVowel(str.charAt(length-1)) ? 1 : 0);
}
private static boolean isVowel(char charAt) {
if(charAt == 'a' || charAt == 'e' || charAt == 'i' || charAt == 'o' || charAt == 'u' || charAt == 'A' || charAt == 'E' || charAt == 'I' || charAt == 'O' || charAt == 'U')
return true;
return false;
}
Output:
Input: NgDevelOper.com
5
Just browsed around admtechbong88… Looks clean! Site design is good, and I hope they got what I’m lookin’ for. Let’s see what happens!
Alright folks, gotta say ee11betcom is pretty slick! Been using it for a bit now and the interface is smooth. Give it a try, you might just like it! Check it out here: ee11betcom
Heard Luckia has a spot down in Valencia. luckiavalencia Might pop by if I’m ever in the area. Probably a fun place to catch a game and grab a beer.
Yo! Checked out malinacasinosport the other day and it’s got a good vibe. If you love sports betting with a casino twist, you should check that. Here’s the link to it: malinacasinosport