In this tutorial, we will discuss Java code to reverse order triangle number patterns. We will see some reverse Floyd’s triangle number patterns, using nested for loop.
import java.util.Scanner; public class RevNum_pattern1{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); //Scanner class in java System.out.print("Enter the rows you want"); int rows=sc.nextInt(); System.out.println(""); for (int i=1; i<=rows; i++){ for (int j=i; j>=1; j--){ System.out.print(j); } System.out.println(); } } }
When the above code is executed, it produces the following results:
Enter the rows you want :8 1 21 321 4321 54321 654321 7654321 87654321
In this Floyd’s triangle pattern, numbers are arranged to reverse order in every line – used nested for loop
import java.util.Scanner; public class RevNum_pattern2{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); //Scanner class in java System.out.print("Enter the number of rows you want"); int rows=sc.nextInt(); System.out.println(""); while(rows>=1){ int j=rows; while(j>=1){ System.out.print(j); j--; } rows--; System.out.println(); } } }
When the above code is executed, it produces the following results:
Enter the number of rows you want:6 654321 54321 4321 321 21 1
import java.util.Scanner; public class RevNum_pattern3{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); //Scanner class in java System.out.print("Enter the number of rows you want"); int rows=sc.nextInt(); System.out.println(""); while(rows>=1){ int j=8; while(j>=rows){ System.out.print(j); j--; } rows--; System.out.println(); } } }
When the above code is executed, it produces the following results:
Enter the number of rows you want: 8 8 87 876 8765 87654 876543 8765432 87654321
import java.util.Scanner; public class RevNum_pattern4{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); //Scanner class in java System.out.print("Enter the rows you want :"); int rows=sc.nextInt(); System.out.println(""); while(rows>0){ for (int i=1; i<=rows; i++){ System.out.print(rows); } System.out.println(" "); rows--; } } }
When the above code is executed, it produces the following results:
Enter the rows you want: 9 999999999 88888888 7777777 666666 55555 4444 333 22 1
Similar post
Floyd’s triangle number pattern using for loop in C
Floyd’s triangle pattern using nested for loop in Java
Floyd’s triangle pattern using nested while loop in Java
Hollow pyramid triangle pattern in C++ language
Rhombus pattern in Java using for loop
Rhombus pattern in C using while loop
Rhombus pattern in C++ using do-while loop
Suggested for you
Nested for loop in C++ language
Nested for loop in Java language
Nested for loop in Python language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…