In this tutorial, we will discuss the concept of Java code to display patterns using do while loop.
In Java, we can use for loop, while loop, do-while loop to display various number, star, alphabet and binary number patterns
In this topic, we demonstrate how to display print some number and star patterns using the nested do-while loop in Java language.
Program 1
class DoWhilepattern1{ public static void main(String args[]){ int i=0; do{ int j=1; while(j<=6) { System.out.print(j); j++; } System.out.println(); i++; } while(i<=6); } }
When the above code is compiled and executed, it produces the following results
123456 123456 123456 123456 123456 123456
Program 2
class NestedDoWhile1{ public static void main(String args[]){ int row=1,column=1; int x; do{ x=6; do{ System.out.print(""); x--; }while(x>=row); column=1; do{ System.out.print(column+" "); column++; }while(column<=row); System.out.println(" "); row++; }while (row<=6); } }
When the above code is compiled and 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
Program 3
class DoWhilepattern1{ public static void main(String args[]){ int i=0; do{ int j=1; while(j<=8) { System.out.print("*"); j++; } System.out.println(); i++; } while(i<=6); } }
When the above code is compiled and executed, it produces the following results
******** ******** ******** ******** ******** ******** ********
Program4
class NestedDoWhile{ public static void main(String args[]){ int row=1,column=1; int x; do{ x=4; do{ System.out.print(""); x--; }while(x>=row); column=1; do{ System.out.print("*"+" "); column++; }while(column<=row); System.out.println(" "); row++; }while (row<=5); } }
When the above code is compiled and executed, it produces the following results
* ** *** **** *****
Similar post
Java program to print star pyramid pattern
C program to print star pyramid pattern
C++ program to print star pyramid pattern
Python program to print star pyramid pattern
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
Do-while loop in Java language
Nested for loop in Java language
Nested for loop in C++ language
Nested for loop in Python language
10 simple ways to add two numbers in Java In this article, we will discuss…
Write a Python program to find the first n prime numbers In this article we…
Python: Calculate Average of odd and even in a list using loops In this post,…
Python: Average of Odd & Even Numbers from User Input In this post, we will…
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…