Count of substrings consisting only of vowels | Java program to Count all substrings in a string which contains only vowels ; Function to check vowel or not ; Function to find largest string which satisfy condition ; Check if current character is vowel ; Increment count ; Count all possible substrings of calculated length ; Reset the length ; Add remaining possible substrings consisting of vowels occupying last indices of the string ; Driver Program
import java . io . * ; public class GFG { static boolean isvowel ( char x ) { return ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } static int CountTotal ( String str ) { int ans = 0 ; int n = str . length ( ) ; char [ ] s = str . toCharArray ( ) ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isvowel ( s [ i ] ) ) cnt += 1 ; else { ans += ( cnt * ( cnt + 1 ) / 2 ) ; cnt = 0 ; } } if ( cnt != 0 ) ans += ( cnt * ( cnt + 1 ) / 2 ) ; return ans ; } static public void main ( String [ ] args ) { String s = " geeksforgeeks " ; System . out . println ( CountTotal ( s ) ) ; } }