Floyd's triangle

Java code to reverse order triangle number patterns

Java code to reverse order triangle number patterns

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.

Floyd’s triangle number pattern

Pattern program 1

Floyd’s triangle reserved pattern
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

Pattern program 2

 

floyd’s triangle pattern 2

 

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

 

Pattern program 3

 

Floyd’s triangle reserved pattern
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

Pattern program 4

 

Reverse number pattern
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 Java language

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 C language

Nested for loop in Python language

 

 

 

CPP program to print Floyd's triangle number patterns
C program to pyramid number pattern
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

1 month ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

9 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

9 months ago