In this tutorial, we will discuss a concept of Java program to display integrated pyramid number pattern using while loop
In the Java programming 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 integrated pyramid number pattern using while loop in Java 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 i=1; while(i<=row){//print upper part of shape j=i; while(j<=row){ System.out.print(j); j++; } i++; System.out.print("\n"); } i=row-1; while(i>=1){ j=i; while(j<=row){ System.out.print(j); 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 i=1; while(i<=row){//print upper part of shape j=1; while(j<i){ System.out.print(" ");//print space j++; } j=i; while(j<=row){ System.out.print(j); j++; } i++; System.out.print("\n"); } i=row-1; while(i>=1){//print lower part of shape j=1; while(j<i){ System.out.print(" "); j++; } j=i; while(j<=row){ System.out.print(j); j++; } i--; System.out.print("\n"); } } }
When the above code is executed, it produces the following results
Program 3
import java.util.Scanner; class DoublePyramidWhile7{ 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();//get input from user i=rows; while(i>=1){ j=1; while(j<=i){ System.out.print(j); j++; } System.out.print("\n"); i--; } i=1; while( i<rows){//print lower part of shape j=1; while(j<=i){ System.out.print(j); j++; } System.out.print("\n"); i++; } } }
When the above code is executed, it produces the following results
program 4
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 i=1; while(i<=row){//print upper part of shape j=1; while(j<=i){ System.out.print(" ");//print space j++; } j=i; while(j<=row){ System.out.print(j+" ");//print number with space j++; } i++; System.out.print("\n"); } i=row-1; while(i>=1){//print lower part of shape j=1; while(j<=i){ System.out.print(" "); j++; } j=i; while(j<=row){ System.out.print(j+" "); j++; } i--; System.out.print("\n"); } } }
When the above code is executed, it produces the following results
Program 5
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 i=1; while(i<=row){//print upper part of shape j=1; while(j<=row-i){ System.out.print(" ");//print space j++; } j=1; while(j<=i){ System.out.print(j+" ");//print number with space j++; } i++; System.out.print("\n"); } i=1; while(i<=row-1){//print lower part of shape j=1; while(j<=i){ System.out.print(" "); j++; } j=1; while(j<=row-i){ System.out.print(j+" "); j++; } i++; System.out.print("\n"); } } }
When the above code is executed, it produces the following results
Program 6
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();//get input from user i=1; while(i<=rows){ for(j=1; j<=i; j++){ System.out.print(j); } j=i*2; while(j<rows*2){ System.out.print(" "); j++; } k=i; while( k>=1){ System.out.print(k); k--; } System.out.print("\n"); i++; } } }
When the above code is executed, it produces the following results
Program 7
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();//get input from user i=rows; while(i>=1){ //parent while loop j=rows; while(j>=1+rows-i){ System.out.print(j); j--; } j=i*2; while(j<rows*2-1){ System.out.print(" "); j++; } k=1+rows-i; while( k<=rows){ if(k!=1) System.out.print(k); k++; } System.out.print("\n"); i--; } } }
When the above code is executed, it produces the following results
Program 8
import java.util.Scanner; class DoublePyramidWhile6{ 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();//get input from user i=rows; while(i>=1){ j=1; while(j<=i){ System.out.print(j); j++; } j=i*2; while( j<rows*2-1){ System.out.print(" "); j++; } k=i;; while( k>=1){ if(k!=rows) System.out.print(k); k--; } System.out.print("\n"); i--; } } }
When the above code is executed, it produces the following results
Similar post
C program to display integrated pyramid number pattern using while loop
C++ program to display integrated pyramid number pattern using while loop
Suggested for you
Data types and variable in Java language
Nested while loop in Java language
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…