Java Program to Print Right Triangle Number Pattern

Write a Java program to print the right angled triangle number pattern using for loop.

import java.util.Scanner;

public class RightTriangleNumber1 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc = new Scanner(System.in);	
		
		System.out.print("Right Triangle Number Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Right Angled Triangle Number Pattern");	
		
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= i; j++ ) 	
			{
				System.out.printf("%d ", i);
			}
			System.out.println();
		}
	}
}
Java Program to Print Right Triangle Number Pattern

This Java example displays the numbers in right angled triangle pattern using a while loop.

import java.util.Scanner;

public class RightTriangleNumber2 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc = new Scanner(System.in);	
		
		int i = 1, j;
		
		System.out.print("Right Triangle Number Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Right Angled Triangle Number Pattern");
		
		while (i <= rows ) 
		{
			j = 1 ;
			
			while( j <= i ) 	
			{
				System.out.printf("%d ", i);
				j++;
			}
			System.out.println();
			i++;
		}
	}
}
Right Triangle Number Pattern Rows = 9
Right Angled Triangle Number Pattern
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
6 6 6 6 6 6 
7 7 7 7 7 7 7 
8 8 8 8 8 8 8 8 
9 9 9 9 9 9 9 9 9 

Java program to print right triangle number pattern using do while loop.

import java.util.Scanner;

public class RightTriangleNumber3 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc = new Scanner(System.in);	
		
		System.out.print("Right Triangle Number Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Right Angled Triangle Number Pattern");
		int i = 1, j;
		
		do
		{
			j = 1 ;
			
			do	
			{
				System.out.printf("%d ", i);

			} while( ++j <= i );
			
			System.out.println();

		} while (++i <= rows );
	}
}
Right Triangle Number Pattern Rows = 8
Right Angled Triangle Number Pattern
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
6 6 6 6 6 6 
7 7 7 7 7 7 7 
8 8 8 8 8 8 8 8