Modify the string by swapping continuous vowels or consonants | Java implementation of the above approach ; Function to check if a character is a vowel ; Function to swap two consecutively repeated vowels or consonants ; Traverse through the length of the string ; Check if the two consecutive characters are vowels or consonants ; swap the two characters ; Driver code
class GFG { static boolean isVowel ( char c ) { c = Character . toLowerCase ( c ) ; if ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) { return true ; } return false ; } static String swapRepeated ( char str [ ] ) { for ( int i = 0 ; i < str . length - 1 ; i ++ ) { char c = 0 ; if ( ( isVowel ( str [ i ] ) && isVowel ( str [ i + 1 ] ) ) || ( ! isVowel ( str [ i ] ) && ! isVowel ( str [ i + 1 ] ) ) ) { c = str [ i ] ; str [ i ] = str [ i + 1 ] ; str [ i + 1 ] = c ; } } return String . valueOf ( str ) ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; System . out . println ( swapRepeated ( str . toCharArray ( ) ) ) ; } }