Write a Java program to print right triangle of numbers in reverse order using for loop.
import java.util.Scanner; public class RightTriangleNumReverse1 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Reverse Right Triangle Number Pattern Rows = "); int rows = sc.nextInt(); System.out.println("Printing Right Triangle of Numbers in Reverse"); for (int i = rows ; i >= 1; i-- ) { for (int j = rows ; j >= i; j-- ) { System.out.print(j + " "); } System.out.println(); } } }
This Java example displays the reverse ordered numbers in the right angled triangle number pattern using a while loop.
import java.util.Scanner; public class RightTriangleNumReverse2 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Reverse Right Triangle Number Pattern Rows = "); int rows = sc.nextInt(); System.out.println("Printing Right Triangle of Numbers in Reverse"); int i = rows, j; while (i >= 1 ) { j = rows ; while(j >= i) { System.out.print(j + " "); j--; } System.out.println(); i--; } } }
Reverse Right Triangle Number Pattern Rows = 8
Printing Right Triangle of Numbers in Reverse
8
8 7
8 7 6
8 7 6 5
8 7 6 5 4
8 7 6 5 4 3
8 7 6 5 4 3 2
8 7 6 5 4 3 2 1
Java program to print right angled triangle of numbers in reverse pattern using do while loop.
import java.util.Scanner; public class RightTriangleNumReverse3 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Reverse Right Triangle Number Pattern Rows = "); int rows = sc.nextInt(); System.out.println("Printing Right Triangle of Numbers in Reverse"); int i = rows, j; do { j = rows ; do { System.out.print(j + " "); } while(--j >= i); System.out.println(); } while (--i >= 1 ) ; } }
Reverse Right Triangle Number Pattern Rows = 14
Printing Right Triangle of Numbers in Reverse
14
14 13
14 13 12
14 13 12 11
14 13 12 11 10
14 13 12 11 10 9
14 13 12 11 10 9 8
14 13 12 11 10 9 8 7
14 13 12 11 10 9 8 7 6
14 13 12 11 10 9 8 7 6 5
14 13 12 11 10 9 8 7 6 5 4
14 13 12 11 10 9 8 7 6 5 4 3
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 2 1