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
Suggested for you
For loop in C language
For loop in Python language
Nested for loop in Java language
Nested for loop in C++ language
Nested for loop in Python language
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…