Floyd's triangle

Floyd’s triangle number pattern Using nested while loop in Java

Floyd’s triangle number pattern Using nested while loop in Java

In this tutorial ,we will learn about Floyd’s triangle Number pattern using nested while loop in Java.

We can use nested while loop in Java to write coding for Squares, rectangles, Floyed triangle ,Pyramid triangles and many other shapes.

In this tutorial, we will learn about some of the Floyd’s triangle shapes and how to write coding for that in Java programming language.

Program to print triangle pattern using number

Floyd’s triangle number pattern 1

pattern 1

class WhilepatternA{
public static void main(String args[]){
        int i=1;
        while(i<=10){//outer while loop
            int j=1;
            while(j<=i){//inner while loop
                System.out.print(j+" ");
                
                j++;
        }
        System.out.println();
        i++;
   }        
   }
}

When the above code is executed, it produces the following results:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10

 

pattern 2

class WhilepatternA{
public static void main(String args[]){
        int i=1;
        while(i<=10){//outer while loop
            int j=1;
            while(j<=i){//inner while loop
                System.out.print(i+" ");
                
                j++;
        }
        System.out.println();
        i++;
   }        
   }
}

When the above code is executed, it produces the following results:

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10 10 10

 

Floyd’s triangle number pattern 2

pattern 3

import java.util.Scanner;
class Whilepatterns{
public static void main(String args[]){
  System.out.println("floyd's triangle number pattren: ");
Scanner scan=new Scanner(System.in);
//cretae a new scanner object
  System.out.println("Enter the number of row of you want: ");
   int rows =scan.nextInt();//get the input from user
int row=1;
   System.out.println("Here your floyd's triangle ");
    int i=1,j;  
    while(i<=rows){//outer while loop
      j=1;
      while(j<=i){//inner while loop
        System.out.print(row+" ");
        row++;
        j++;
    }
    System.out.println();
    i++;
   }        
   }
}

 

When the above code is executed, it produces the following results:

When enter  rows value is 7

Floyd's triangle number patterns
Enter the number of rows of you want:
7
Here your Floyd's triangle
1
2 3
4 5 6
7 8 9 10
11 12  13 14 15
16 17 18 1 20 21
22 23 24 25 26 27 28

When enter  rows value is 10

Floyd's triangle number patterns 
Enter the number of rows of you want: 7 
Here your Floyd's triangle 
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21 
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55

Floyd’s triangle number pattern 4

Pattern 4

public class WhilePattern2{
    public static void main (String args[]){
int i=1,j,k,m1=10,m2=10,num=0;
while(i<=m1){
k=1;
while(k<m1-(m1-i)){
System.out.print(" ");
k++;
}
num=m2-i;
j=1;
while(j<=num){
    System.out.print(m1-(m1-j));
    j++;
}
i++;
System.out.println(" ");
}
    }
}

When the above code is executed, it produces the following results:

1 2 3 4 5 6 7 8 9 
   1 2 3 4 5 6 7 8 
      1 2 3 4 5 6 7 
         1 2 3 4 5 6 
            1 2 3 4 5
               1 2 3 4
                  1 2 3 
                     1 2 
                        1

 

Floyd’s triangle number pattern 5

Pattern 5

class While_pattern5{
public static void main(String args[]){
int i=1;
int j=1;
int k=1;
int m1=10;

while(i<m1){
k=1;
    while(k<m1-i){
        System.out.print(' ');
k++;
}

while(j>0){
System.out.print(m1-(m1-j));
j--;

}
i++;
j+=i;
System.out.println("");

}
System.out.println("");

}
}

When the above code is executed, it produces the following results:

                1
              21
            321
          4321
        54321
      654321
    7654321
  87654321
987654321

 

Floyd’s triangle number pattern 6

Pattern 6

import java.util.Scanner; //import scanner package 
public class Floyds_trangle7
{ 
public static void main(String args[]) { 
System.out.println("welcome to print floyd's triangle in Java"); //add a discription 
System.out.println("please enter a number of rows :"); 
Scanner sc=new Scanner(System.in); //user input metod 
int rows=sc.nextInt(); //get input from user to print floyd's triangle 
int i=rows;
while(i>=1){
    int j=rows;
    while(j>=i){
        System.out.print(j);
    j--;
    
}
i--;
System.out.println();
}
}
}

When the above code is executed, it produces the following results:

welcome to print Floyd's triangle in Java
please enter a number of rows :
6
6
65
654
6543
65432
654321

 

There are other Java language keywords that are similar to the this post

While keyword in Java

if keyword in Java

 

Suggested for you

While loop in Java language

While loop in C++ language

While loop in C language

While loop in Python language

Nested for loop in Java

Nested do while loop in Java language

C program for Floyd's triangle Number pattern using nested for
Inverted Pyramid number pattern in Java
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.

View Comments

  • Это однозначно фантастические идеи по поводу блогов.

    Вы затронули некоторые уникальные вещи здесь.
    Так держать, пишите еще!

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