Google News
logo
Java Program to Print the following Pattern-2
Here's a Java program to print the following pattern :

*****
****
***
**
*
Program :
public class Pattern {
    public static void main(String[] args) {
        for (int i = 5; i >= 1; i--) {
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
Output :
*****
****
***
**
*
This program uses two nested for loops. The outer loop iterates over the rows of the pattern in reverse order, and the inner loop iterates over the columns.

The inner loop prints a * character for each column, and the outer loop adds a newline character at the end of each row.