In this tutorial, we will discuss a concept of Display integrated pyramid star pattern in Java using while loop.
In Java language, we can use for loop , while loop and do-while loop to display different number (binary, decimal), alphabets or star pattern programs.
In this article, we are going to learn how to Display double pyramid star pattern using while loop in Java programming language
Program 1
import java.util.Scanner; class DoublePyramidWhile{ public static void main(String args[]){ int i,j; //variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the number of rows: "); int row=scan.nextInt(); //get input from user for number of rows i=1; while(i<=row){ j=i; while(j<=row){ //print upper part of pattern System.out.print("*"); j++; } i++; System.out.print("\n"); } i=row-1; while(i>=1){ //print lower part of pattern j=i; while(j<=row){ System.out.print("*"); j++; } i--; System.out.print("\n"); } } }
When the above code is executed, it produces the following results
Program 2
import java.util.Scanner; class DoublePyramidWhile1{ public static void main(String args[]){ int i,j; //variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the number of rows: "); int row=scan.nextInt(); //get input from user for number of rows i=1; while(i<=row){ j=1; while(j<i){ //print upper part of pattern System.out.print(" "); j++; } j=i; while(j<=row){ System.out.print("*"); j++; } i++; System.out.print("\n"); } i=row-1; while(i>=1){ //print lower part of pattern j=1; while(j<i){ System.out.print(" "); j++; } j=i; while(j<=row){ System.out.print("*"); j++; } i--; System.out.print("\n"); } } }
When the above code is executed, it produces the following results
Program 3
import java.util.Scanner; class DoublePyramidWhile2{ public static void main(String args[]){ int i,j; //variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the number of rows: "); int row=scan.nextInt(); //get input from user for number of rows i=1; while(i<=row){ j=1; while(j<=i){ //print upper part of pattern System.out.print(" "); j++; } j=i; while(j<=row){ System.out.print("*"+" "); j++; } i++; System.out.print("\n"); } i=row-1; while(i>=1){ //print lower part of pattern j=1; while(j<=i){ System.out.print(" "); j++; } j=i; while(j<=row){ System.out.print("*"+" "); j++; } i--; System.out.print("\n"); } } }
When the above code is executed, it produces the following results
Program 4
import java.util.Scanner; class DoublePyramidWhile3{ public static void main(String args[]){ int i,j,k; //variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the number of rows: "); int row=scan.nextInt(); //get input from user for number of rows i=1; while(i<=row){ j=1; while(j<=row-i){ //print upper part of pattern System.out.print(" "); j++; } j=1; while(j<=i){ System.out.print("*"+" "); j++; } i++; System.out.print("\n"); } i=1; while(i<=row-1){ //print lower part of pattern j=1; while(j<=i){ System.out.print(" "); j++; } j=1; while(j<=row-i){ System.out.print("*"+" "); j++; } i++; System.out.print("\n"); } } }
When the above code is executed, it produces the following results
Program 5
import java.util.Scanner; class DoublePyramidWhile4{ public static void main(String args[]){ int i,j,k; //variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input //get input from the user for rows System.out.print("Enter the number of rows: "); int rows=scan.nextInt(); i=1; while(i<=rows){ for(j=1; j<=i; j++){ //print upper part of pattern System.out.print("*"); } j=i*2; while(j<rows*2){ //print lower part of pattern System.out.print(" "); j++; } k=i; while( k>=1){ System.out.print("*"); k--; } System.out.print("\n"); i++; } } }
When the above code is executed, it produces the following results
Program 6
import java.util.Scanner; class DoublePyramidWhile5{ public static void main(String args[]){ int i,j,k; //variable declaration Scanner scan=new Scanner(System.in); //create a scanner object for input //get input from the user for rows System.out.print("Enter the number of rows: "); int rows=scan.nextInt(); i=rows; while(i>=1){ //parent while loop j=rows; while(j>=1+rows-i){ //print upper part of pattern System.out.print("*"); j--; } j=i*2; while(j<rows*2-1){ System.out.print(" "); j++; } k=1+rows-i; while( k<=rows){ //print lower part of pattern if(k!=1) System.out.print("*"); k++; } System.out.print("\n"); i--; } } }
When the above code is executed, it produces the following results
Similar post
Display integrated pyramid star pattern in C++ using while loop
Display integrated pyramid star pattern in C using while loop
C code to print double pyramid star pattern
Java code to print double pyramid star pattern
C++ code to print double pyramid star pattern
Suggested for you
Data types and variable in Java language
While loop in Java language
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…