Right-Angled Triangle of Stars
This program prints a right-angled triangle of stars.
Problem Statement
Write a Java program that prints a right-angled triangle of stars with 5 rows.
Source Code
| 1 | public class RightTriangleStars { |
| 2 | public static void main(String[] args) { |
| 3 | for(int i=1; i<=5; 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 runs 5 times, each iteration representing a row, while the inner loop prints stars equal to the current row number, so stars increase row by row forming a right-angled triangle. This demonstrates how nested loops can build progressive patterns.