KnowledgeBoat Logo

Java Pattern Programs

Write a program in Java to display the following pattern:

5 4 3 2 1
5 4 3 2
5 4 3
5 4
5

Java

Java Nested for Loops

ICSE

196 Likes

Answer

public class KboatPattern
{
    public void displayPattern() {
        for (int i = 1; i <= 5; i++) {
            for (int j = 5; j >= i; j--) {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

Output

BlueJ output of Write a program in Java to display the following pattern: 5 4 3 2 1 5 4 3 2 5 4 3 5 4 5

Answered By

94 Likes