Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Floyd’s triangle number pattern using while loop in Java

Posted on September 15, 2017January 24, 2020

Table of Contents

  • Floyd’s triangle number pattern using while loop in Java
    • Triangle  number pattern using while loop in Java
    • Triangle pattern 1
    • Triangle pattern 2
    • Triangle  pattern 3
    • Triangle pattern 4
    • Related

Floyd’s triangle number pattern using while loop in Java

In this tutorial, we will discuss Floyd’s triangle number pattern using while loop in Java.

Triangle  number pattern using while loop in Java

We can print a lot of patterns (Floyd’s triangle or pyramid triangle)using nested while loop in java.

This example explains how to create Floyd triangle using java Nested while loop

Triangle pattern 1

How to print this number pattern using nested while loop in Java

123456
12345
1234
123
12
1

Program 1

Floyd,s triangle number pattern using while loop in Java
Example

When the above code is executed, the following output is displayed

123456
12345
1234
123
12
1

Triangle pattern 2

How to print this number pattern using nested while loop in Java

1
12
123
1234
12345
123456

Program 2

Floyd,s triangle number pattern using while loop in Java
Example

When the above code is executed, the following output is displayed

1
12
123
1234
12345
123456

Triangle  pattern 3

Program 3

public class WhilePattern2{
  public static void main (String args[]){
int i=1,j=1,k=1,n1=9,n2=10,count=0;
while(i<=n1){
k=1;
while(k<n1-(n1-i)){
System.out.print(" ");
k++;

}
count=n2-i;
j=1;
while(j<=count){
  
  System.out.print(n1-(n1-j));
  j++;
}
i++;

System.out.println(" ");

}
  }
}

When the above code is executed, it produces the following result

Floyd's triangle number pattern using while loop in Java
Pattern 3

Triangle pattern 4

Program 4

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

When the above code is executed, it produces the following result

Floyd's triangle number pattern using while loop in Java
Pattern 4

 

 

While  loop in Java                     While loop in C Language

Nested while loop in Java           Nested while loop in C Language

Nested for loop in Java              Nested for loop in C Language

Floyd triangle using for loop in Java

Rectangle, Square and Table in Java          Pyramid print in C
Pyramid Triangle in JaVa                           Floyd,s Triangle in C
Rectangle, Square in C++                          Rectangle, Square in C
Floyd,s Triangle in C++                              Pyramid print in C++

Related

2 thoughts on “Floyd’s triangle number pattern using while loop in Java”

  1. Kamila says:
    March 19, 2019 at 7:22 am

    Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging
    Dot Net Training In Chennai | Dot Net Training Institute In Chennai | Dot Net Course In Chennai
    Software Testing Training Chennai | Software Testing Course In Chennai | Testing Courses In Chennai
    Java Training Institute in Chennai | Core Java Training in Chennai | Java Course and Certification
    PHP Course in Chennai | PHP Training Institute in Chennai | PHP Course and Certification

  2. vannan says:
    April 17, 2019 at 3:12 am

    thank you

Comments are closed.

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes