In this tutorial, we will write a program to print the right triangle star pattern in java. Before that, you may go through the following topic in java.
It also can be called mirrored right triangle number pattern in java or a half pyramid pattern in java. The program takes a user input for the number of rows and displays it accordingly.
Java Program to Print Right Triangle Star Pattern
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import java.util.Scanner; public class Main { public static void main(String args[]) { int i, j, num; Scanner sc = new Scanner(System.in); System.out.print("Enter the number of rows: "); num = sc.nextInt(); for (i = 1; i <= num; i++) { for (j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(""); } } } |
Output: