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.
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
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
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
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
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
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
How to find reverse number using method In this article, we will discuss the concept…
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…
View Comments
Это однозначно фантастические идеи по поводу блогов.
Вы затронули некоторые уникальные вещи здесь.
Так держать, пишите еще!
Thank you