KnowledgeBoat Logo

Computer Applications

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

34 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();
        }
    }
}

Variable Description Table

Program Explanation

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

12 Likes


Related Questions