Number of strings which starts and ends with same character after rotations | Java program for the above approach ; Function to find the count of string with equal end after rotations ; To store the final count ; Traverse the string ; If current character is same as the previous character then increment the count ; Return the final count ; Driver Code ; Given string ; Function call
class GFG { static int countStrings ( String s ) { int cnt = 0 ; for ( int i = 1 ; i < s . length ( ) - 1 ; i ++ ) { if ( s . charAt ( i ) == s . charAt ( i + 1 ) ) { cnt ++ ; } } return cnt ; } public static void main ( String [ ] args ) { String str = " aacbb " ; System . out . println ( countStrings ( str ) ) ; } }