Here is a java program to print a right triangle pattern of natural numbers using for loops.
Java program to print natural number triangle pattern
package com.tcc.java.programs; import java.util.*; public class NaturalNumberTriangle { public static void main(String args[]) { int rows, i, j, count = 1, star = 0; Scanner in = new Scanner(System.in); System.out.println("Enter number of rows in pattern"); rows = in.nextInt(); for (i = 1; i <= rows; i++) { for (j = 1; j <= i; j++) { System.out.print(count + " "); count++; } System.out.print("\n"); } } }Output
Enter number of rows in pattern 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Recommended Posts