Generate an N | Java program to implement the above approach ; Function to generate a String of length N having longest palindromic subString of length K ; Fill first K characters with ' a ' ; Stores a non - palindromic sequence to be repeated for N - k slots ; Print N - k remaining characters ; Driver Code ; Given N and K
import java . util . * ; class GFG { static void String_palindrome ( int N , int K ) { for ( int i = 0 ; i < K ; i ++ ) System . out . print ( " a " ) ; String s = " bcd " ; for ( int i = 0 ; i < N - K ; i ++ ) System . out . print ( s . charAt ( i % 3 ) ) ; } public static void main ( String [ ] args ) { int N = 5 , K = 3 ; String_palindrome ( N , K ) ; } }