KnowledgeBoat Logo

Java Pattern Programs

Write a program to display the pattern:

A B C D E
A B C D A
A B C A B
A B A B C
A A B C D

Java

Java String Handling

ICSE

4 Likes

Answer

public class KboatStringPattern
{
    public static void main(String args[]) {
        String word = "ABCDE";
        int len = word.length();
        
        for (int i = 0; i < len; i++) {
            for (int j = 0; j < len - i; j++) {
                System.out.print(word.charAt(j));
            }
            for (int k = 0; k < i; k++) {
                System.out.print(word.charAt(k));
            }
            System.out.println();
        }
    }
}

Output

BlueJ output of Write a program to display the pattern: A B C D E A B C D A A B C A B A B A B C A A B C D

Answered By

1 Like