Count N | Java program to illustrate Count of N - length strings consisting only of vowels sorted lexicographically ; to keep the string in lexicographically sorted order use start index to add the vowels starting the from that index ; base case : if string length is 0 add to the count ; if last character in string is ' e ' add vowels starting from ' e ' i . e ' e ' , ' i ' , ' o ' , ' u ' ; decrease the length of string ; char arr [ 5 ] = { ' a ' , ' e ' , ' i ' , ' o ' , ' u ' } ; starting from index 0 add the vowels to strings
import java . util . * ; public class Main { static int countstrings ( int n , int start ) { if ( n == 0 ) { return 1 ; } int cnt = 0 ; for ( int i = start ; i < 5 ; i ++ ) { cnt += countstrings ( n - 1 , i ) ; } return cnt ; } static int countVowelStrings ( int n ) { return countstrings ( n , 0 ) ; } public static void main ( String [ ] args ) { int n = 2 ; System . out . print ( countVowelStrings ( n ) ) ; } }