Binary String of given length that without a palindrome of size 3 | JAVA program find a binary String of given length that doesn 't contain a palindrome of size 3. ; Printing the character according to i ; Driver code
class GFG { static void generateString ( int n ) { String s = " " ; for ( int i = 0 ; i < n ; i ++ ) s += ( ( i & 2 ) > 1 ? ' b ' : ' a ' ) ; System . out . println ( s ) ; } public static void main ( String [ ] args ) { int n = 5 ; generateString ( n ) ; n = 8 ; generateString ( n ) ; n = 10 ; generateString ( n ) ; } }