Right Triangle Star Pattern in Java
Java program to print a right-angled triangle star pattern using nested loops.
Last updated: 11 January 2026
Method 1: Using Nested For Loops
Standard approach.
Main.javaRun in Compiler →
public class RightTriangle {
public static void main(String[] args) {
int rows = 5;
for (int i = 1; i <= rows; ++i) {
for (int j = 1; j <= i; ++j) {
System.out.print("* ");
}
System.out.println();
}
}
}Output:
* * * * * * * * * * * * * * *
Explanation
Outer loop runs for each row. Inner loop prints stars equal to the current row number.
Frequently Asked Questions
Try This Program
Copy this code and run it in our free online Java compiler.
Open Java Compiler