Computer Applications

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

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

Variable Description Table

Program Explanation

Output

Answered By

108 Likes


Related Questions