KnowledgeBoat Logo

Java Pattern Programs

Write a program to accept a word (say, BLUEJ) and display the pattern:

J
E E
U U U
L L L L
B B B B B

Java

Java String Handling

ICSE

24 Likes

Answer

import java.util.Scanner;

public class KboatStringPattern
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a word: ");
        String word = in.nextLine();
        int len = word.length();
        
        for (int i = len - 1; i >= 0; i--) {
            for (int j = len - 1; j >= i; j--) {
                char ch = word.charAt(i);
                System.out.print(ch);
            }
            System.out.println();
        }
    }
}

Output

BlueJ output of Write a program to accept a word (say, BLUEJ) and display the pattern: J E E U U U L L L L B B B B B

Answered By

10 Likes