Skip to main content

Command Palette

Search for a command to run...

Inverted Right-Angle

Published
1 min readView as Markdown

Example: Inverted Right-Angle Triangle Pattern using Stars

This pattern looks like this:

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

Java Code to Print the Pattern:

public class InvertedPattern {
    public static void main(String[] args) {
        int n = 5; // You can change the value of n to print more or fewer rows

        for (int i = n; i >= 1; i--) {
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }
            System.out.println(); // Move to the next line after printing each row
        }
    }
}

Explanation:

  • The outer loop (for (int i = n; i >= 1; i--)) controls the number of rows, starting from n and decreasing to 1.

  • The inner loop (for (int j = 1; j <= i; j++)) prints i number of stars in each row.

  • System.out.print("*") prints a star without moving to the next line.

  • System.out.println() moves the cursor to the next line after each row is printed.

You can adjust n to change the number of rows in the pattern.

More from this blog

Amit singh's blog

235 posts