We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 944c2d4 commit 12e95d0Copy full SHA for 12e95d0
CountVowelRecursive.java
@@ -0,0 +1,22 @@
1
+package ds.algo.solutions;
2
+
3
+public class CountVowelRecursive {
4
5
+ public static void main(String[] args) {
6
7
+ String str = "hello world";
8
+ System.out.println(countVowels(str, str.length() - 1));
9
+ }
10
11
+ private static boolean isVowel(char ch) {
12
+ return ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' ||
13
+ ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
14
15
16
+ private static int countVowels(String str, int pos) {
17
+ if (pos == 1)
18
+ return isVowel(str.charAt(pos - 1)) ? 1 : 0;
19
20
+ return countVowels(str, pos - 1) + (isVowel(str.charAt(pos - 1)) ? 1 : 0);
21
22
+}
0 commit comments