Write a Java program to print the inverted right angled triangle pattern of numbers in reverse order using for loop.
import java.util.Scanner; public class InvertedRightTriReverse1 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Inverted Right Triangle Reverse Numbers Pattern Rows = "); int rows = sc.nextInt(); System.out.println("Inverted Right Triangle of Numbers in Reverse Order"); for (int i = 1 ; i <= rows; i++ ) { for (int j = rows ; j >= i; j-- ) { System.out.print(j + " "); } System.out.println(); } } }
This Java program displays the inverted right angled triangle pattern of the same numbers in each column in reverse order using a while loop.
import java.util.Scanner; public class InvertedRightTriReverse2 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Inverted Right Triangle Reverse Numbers Pattern Rows = "); int rows = sc.nextInt(); System.out.println("Inverted Right Triangle of Numbers in Reverse Order"); int i = 1, j; while (i <= rows ) { j = rows ; while (j >= i ) { System.out.print(j + " "); j--; } System.out.println(); i++; } } }
Inverted Right Triangle Reverse Numbers Pattern Rows = 7
Inverted Right Triangle of Numbers in Reverse Order
7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7
Java program to print inverted right triangle numbers in reverse order using do while loop.
import java.util.Scanner; public class InvertedRightTriReverse3 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Inverted Right Triangle Reverse Numbers Pattern Rows = "); int rows = sc.nextInt(); System.out.println("Inverted Right Triangle of Numbers in Reverse Order"); int i = 1, j; do { j = rows ; do { System.out.print(j + " "); } while (--j >= i ); System.out.println(); } while (++i <= rows ); } }
Inverted Right Triangle Reverse Numbers Pattern Rows = 14
Inverted Right Triangle of Numbers in Reverse Order
14 13 12 11 10 9 8 7 6 5 4 3 2 1
14 13 12 11 10 9 8 7 6 5 4 3 2
14 13 12 11 10 9 8 7 6 5 4 3
14 13 12 11 10 9 8 7 6 5 4
14 13 12 11 10 9 8 7 6 5
14 13 12 11 10 9 8 7 6
14 13 12 11 10 9 8 7
14 13 12 11 10 9 8
14 13 12 11 10 9
14 13 12 11 10
14 13 12 11
14 13 12
14 13
14