In this tutorial, we will write a program to print triangular number patterns in java where the digits are repeated on each row. Before that, you may go through the following topic in java.
The program takes the user input for the number of rows and displays the result using the for loop in java. The program is right angled triangle pattern or you can say half pyramid of numbers with repetition of digits.
Java program to print right triangle pattern with repeatation of digits
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 rows; Scanner sc = new Scanner(System.in); System.out.print("Enter the number of rows: "); rows = sc.nextInt(); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { System.out.print(i + " "); } System.out.println(); } } } |
Output:
Enter the number of rows: 6
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6