In this tutorial, we will discuss a simple concept of the Generate double pyramid number pattern in Java programming language.
In this post, we will learn how to create different types of integrated pyramid number patterns in Java.
we can use for loop, while loop or do while loop to display different integrated pyramid number patterns.
Here, we will use for loop to print different integrated pyramid number patterns
Program 1
import java.util.Scanner; class DoublePyramid1{ public static void main (String args[]){ Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the number of rows\n"); int rows=scan.nextInt();//reads rows from user for(int i=1; i<=rows; i++){ //print upper part for(int j=i; j<=rows; j++){ System.out.print(j+" ");//print number with space } } System.out.println();//move to next line } for(int i=rows-1; i>=1; i--){ //print lower part for(int j=i; j<=rows; j++){ System.out.print(j+" ");//print number with space } System.out.println();//move to next line } } }
When the above code is executed, it produces the following result
Enter the number of rows 6 1 2 3 4 5 6 2 3 4 5 6 3 4 5 6 4 5 6 5 6 6 5 6 4 5 6 3 4 5 6 2 3 4 5 6 1 2 3 4 5 6
Program 2
import java.util.Scanner; class DoublePyramid3{ public static void main (String args[]){ Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the number of rows\n"); int rows=scan.nextInt();//reads rows from user for(int i=rows; i>=0; i--){ //print upper part for(int j=1; j<=i; j++){ System.out.print(j+" ");//print number with space } System.out.println();//move to next line } for(int i=1; i<=rows; i++){ //print lower part for(int j=1; j<=i; j++){ System.out.print(j+" ");//print number with space } System.out.println();//move to next line } } }
When the above code is executed, it produces the following result
Enter the number of rows 6 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6
Program 3
import java.util.Scanner; class DoublePyramid2{ public static void main (String args[]){ Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the number of rows: "); int rows=scan.nextInt();//reads rows from user for(int i=1; i<=rows; i++){ //print upper part for(int j=1; j<=i; j++){ System.out.print(" "); } for(int k=i; k<=rows; k++){ System.out.print(k+" ");//print number with space } System.out.println(); } for(int i=rows-1; i>=1; i--){ //print lower part for(int j=1; j<=i; j++){ System.out.print(" ");//print space } for(int k=i; k<=rows; k++){ System.out.print(k+" ");//print number with space } System.out.println(); } } }
When the above code is executed, it produces the following result
Enter the number of rows: 6 1 2 3 4 5 6 2 3 4 5 6 3 4 5 6 4 5 6 5 6 6 5 6 4 5 6 3 4 5 6 2 3 4 5 6 1 2 3 4 5 6
Program 4
import java.util.Scanner; class DiamondNumber4{ public static void main (String args[]){ Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the number of rows: "); int rows=scan.nextInt();//reads rows from user for(int i=1; i<=rows; i++){ //print upper part for(int j=1; j<i; j++){ System.out.print(" ");//print space } for(int j=i; j<=rows; j++){ System.out.print(j); } System.out.println(); } for(int i=rows-1; i>=1; i--){ for(int j=1; j<i; j++){ System.out.print(" ");//print space } for(int j=i; j<=rows; j++){ //print lower part System.out.print(j);//print number } System.out.println();//move to next line } } }
When the above code is executed, it produces the following result
Enter the number of roes: 6 123456 23456 3456 456 56 6 56 456 3456 23456 123456
Program 5
import java.util.Scanner; class DoublePyramid4{ public static void main (String args[]){ Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("Enter the number of rows: "); int rows=scan.nextInt();//reads rows from user for(int i=1; i<=rows; i++){ //print upper part for(int j=1; j<=rows-i; j++){ System.out.print(" "); } for(int k=1; k<=i; k++){ System.out.print(k+" ");//print number with space } System.out.println(); } for(int i=1; i<=rows-1; i++){ //print lower part for(int j=1; j<=i; j++){ System.out.print(" "); } for(int k=1; k<=rows-i; k++){ System.out.print(k+" ");//print number with space } System.out.println(); } } }
When the above code is executed, it produces the following result
Enter the number of rows: 6 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 1 2 3 4 1 2 3 1 2 1
Similar post
Intergrated pyramid number pattern in C
Intergrated pyramid number pattern in C++
C++ code to Double pyramid star pattern
Java code to Double pyramid star pattern
Java program to Display diamond number pattern using while loop
C++ code to Display diamond number pattern using while loop
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
Display Pyramid star pattern in C
Display Pyramid star pattern in Java
Parallelogram and Hollow Parallelogram star pattern in Java
Parallelogram and Hollow Parallelogram star pattern in C Language
C++ program to Display diamond number pattern using while loop
C program to Display diamond number pattern using while loop
Suggested for you
Nested for loop in Java language
Nested for loop in C++ language
Nested for loop in Python language
If statements in Java language
Nested if statements in Java language
Nested while loop in Java language
Nested while loop in C language
Class and main method in Java language
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…
Java program to check odd or even using recursion In this tutorial, we discuss a…