Number pattern

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 pyramid number pattern 1

 

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 pyramid number pattern 2

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 pyramid number pattern 3

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 pyramid number pattern 4

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 pyramid number pattern 5

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 pyramid number pattern 6

 

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 pyramid number pattern 7

 

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

integrated pyramid number pattern 8

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

While loop in  Java  language

Nested while loop in Java language

Operator in Java language

 

 

C++ Program to display integrated pyramid number pattern using while loop
C program to print combined Pyramid pattern
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago