Java Program to Print Consecutive Numbers Right Triangle Columns

Write a Java program to print consecutive numbers in right angled triangle columns using for loop.

import java.util.Scanner;

public class ConsecutiveNumRightTri1 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc = new Scanner(System.in);	
		
		System.out.print("Consecutive Numbers Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Consecutive Numbers Right Triangle Pattern");
		int k = 1;
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 1 ; j <= i; j++ ) 	
			{
				System.out.print(k++ + " ");
			}
			System.out.println();
		}
	}
}
Java Program to Print Consecutive Numbers Right Triangle Columns 1

Java right triangle of consecutive column numbers program using a while loop.

import java.util.Scanner;

public class ConsecutiveNumRightTri2 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc = new Scanner(System.in);	
		
		System.out.print("Consecutive Numbers Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Consecutive Numbers Right Triangle Pattern");
		int j, i = 1, k = 1;
		
		while (i <= rows ) 
		{
			
			j = 1 ;
			while( j <= i ) 	
			{
				System.out.print(k++ + " ");
				j++;
			}
			System.out.println();
			i++;
		}
	}
}
Consecutive Numbers Right Triangle Pattern Rows = 10
Printing Consecutive Numbers Right Triangle Pattern
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 
29 30 31 32 33 34 35 36 
37 38 39 40 41 42 43 44 45 
46 47 48 49 50 51 52 53 54 55 

Java Program to Print Consecutive Numbers Right Triangle Columns using do while loop.

import java.util.Scanner;

public class ConsecutiveNumRightTri3 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc = new Scanner(System.in);	
		
		System.out.print("Consecutive Numbers Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Consecutive Numbers Right Triangle Pattern");
		int j, i = 1, k = 1;
		
		do
		{		
			j = 1 ;
			do	
			{
				System.out.print(k++ + " ");

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

		} while (++i <= rows );
	}
}
Consecutive Numbers Right Triangle Pattern Rows = 12
Printing Consecutive Numbers Right Triangle Pattern
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 
29 30 31 32 33 34 35 36 
37 38 39 40 41 42 43 44 45 
46 47 48 49 50 51 52 53 54 55 
56 57 58 59 60 61 62 63 64 65 66 
67 68 69 70 71 72 73 74 75 76 77 78