Program to display integrated pyramid number pattern in Java using while loop
- Home
- Number pattern
- Program to display integrated pyramid number pattern in Java using while loop
- On
- By
- 0 Comment
- Categories: Number pattern, pyramid triangle
Program to display integrated pyramid number pattern in Java using while loop
Java program to display integrated pyramid number pattern using while loop
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
Java code to Integrated triangle number patterns
Integrated Triangle number pattern 1
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
Integrated Triangle number pattern 2
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
Integrated Triangle number pattern 3
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
Integrated Triangle number pattern 4
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
Integrated Triangle number pattern 5
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
Integrated Triangle number pattern 6
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
Integrated Triangle number pattern 7
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
Integrated Triangle number pattern 8
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
Java program to display integrated pyramid number pattern using while loop
C++ program to display integrated pyramid number pattern using while loop
C++ code to Integrated triangle patterns using for loop
Java code to Integrated triangle patterns using for loop
Pascal Triangle pattern in Java Language using Array
C Language Pascal Triangle pattern in using 2D Array
Java Language Pascal Triangle pattern in using 2D Array
Java program to star Pyramid pattern
C# program to inverted star Pyramid pattern
Python program to star Pyramid pattern
Suggested for you
Data types and variable in Java language
Nested while loop in Java language