KnowledgeBoat Logo

Java Pattern Programs

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

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

Java

Java String Handling

38 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 = 0; i < len; i++) {
            for (int j = i; j < len; j++) {
                char ch = word.charAt(j);
                System.out.print(ch);
            }
            System.out.println();
        }
    }
}

Variable Description Table

Program Explanation

Output

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

Answered By

14 Likes