Java Program to Print Right Triangle Pattern of Natural Numbers

  • Write a program in Java 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
Java Program to Print Right Triangle Star Pattern
Java Program to Print Inverted Right Triangle Star Pattern
Java Program to Print Pascal Triangle
Java program to Print Square Pattern of Star Character
Java Program to Print Diamond Pattern of Star Character
Java Program to Print Inverted Pyramid Pattern of Stars
Java Program to Print Pyramid Pattern of Stars
Java Program to Count Words in a Sentence
Java Program to Reverse a String
Java Program to Find Length of a String
Java Program to Copy a String
All Java Programs