Inverted Right-Angle
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 fromnand decreasing to1.The inner loop (
for (int j = 1; j <= i; j++)) printsinumber 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.