Java Program to Print Inverted Right Triangle of Consecutive Numbers

Write a Java program to print the inverted right angled triangle of consecutive numbers using a for loop with an example.

import java.util.Scanner;

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

This Java example displays consecutive numbers right angled triangle using a while loop.

import java.util.Scanner;

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

Java Program to print inverted right triangle of consecutive numbers using do while loop.

import java.util.Scanner;

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

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

		} while( --i >= 1 );
	}
}
Inverted Right Triangle Consecutive Number Pattern Rows = 15
Inverted Right Triangle of Consecutive Numbers Pattern
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 
1 2 3 4 5 6 7 8 9 10 11 12 13 
1 2 3 4 5 6 7 8 9 10 11 12 
1 2 3 4 5 6 7 8 9 10 11 
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.