Inverted Triangle of Stars

This program prints an inverted triangle of stars.

Problem Statement

Write a Java program that prints an inverted triangle of stars with 5 rows.

Source Code

1 public class InvertedTriangleStars {
2 public static void main(String[] args) {
3 for(int i=5; i>=1; i--) {
4 for(int j=1; j<=i; j++) {
5 System.out.print("* ");
6 }
7 System.out.println();
8 }
9 }
10 }

Program Output

* * * * * 
* * * * 
* * * 
* * 
* 

Explanation

The outer loop starts at 5 and decreases each iteration, while the inner loop prints stars equal to the current row count, so the pattern shrinks from 5 stars down to 1, demonstrating decremental control of loops and how patterns can reverse growth.

Quick Links to Explore