bonzo bonzo - 1 month ago 10x
Java Question

Java string loop pattern

I'm going through some introductory exercises and I can not understand how to get java to output a string of five letters in the particular pattern shown below.
said pattern

Initially I thought it followed the tribonacci sequence for number of characters per line. Without just printing the line, I can not figure out how to have java logically replicate the pattern. They seem to copy each other, but don't really follow a pattern.


The strings are palindrome and getting its end from the last string, for example; line 2 has "ABA" string, so line 3 will copy "ABA" at its end and will insert character C in the middle, so the final string will be "ABACABA"

String LastPattern="";
        for(int i=0;i<5;i++){
            System.out.println( LastPattern + (char)(65+i) +LastPattern);
            LastPattern=LastPattern + (char)(65+i) +LastPattern;