Java program to create combined Pyramid pattern using while loop

Java program to create combined Pyramid pattern using while loop

In this tutorial, we will discuss a concept of  the Java program to create  Combined Pyramid pattern

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 combined Pyramid pattern  using while loop  in Java language

Program to display combined Pyramid star pattern

Combined Pyramid star pattern 1

Program 1

The Java program allows the user to enter the number of rows then it displays two combined straight pyramid star pattern according to the number of rows.

import java.util.Scanner;
class JointedPyramidwhile1{
public static void main(String args[]){
    int i,j;  //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();
System.out.print("\n");

i=1; 
while(i<=rows){  //parent while loop
    j=i; 
  while(j<=rows){
  System.out.print(" ");//print space
  j++;
  }
  j=1;
  while( j<=2*i-1){
  System.out.print("*");//print star
   j++;
  }
  j=2*i; 
   while(j<=2*rows-1){
  System.out.print(" ");//print space
  j++;
   }
   j=1;
  while( j<=2*i-1){
  System.out.print("*");//print star
  j++;
  }
  System.out.print("\n");//move to next line
i++;
}

}


}

When the above code is executed, it produces the following results

Java program to create combined Pyramid pattern

 

Combined Pyramid star pattern 2

Program 2

The Java program allows the user to enter the number of rows then it displays two combined upside-down pyramid star pattern according to the number of rows.

import java.util.Scanner;
class JointedPyramidwhile2{
public static void main(String args[]){
    int i,j;  //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();
System.out.print("\n");
i=1;
while( i<=rows){//parent while loop
	j=1; 
  while(j<i){
  System.out.print(" ");//print space
   j++;
  }
  j=1; 
  while(j<2*(rows-i+1)){
  System.out.print("*");//print star
   j++;
  }
  j=2; 
   while(j<2*i){
  System.out.print(" ");//print space
  j++;
   }
   j=1;
  while( j<2*(rows-i+1)){
  System.out.print("*");//print star
   j++;
  }
  System.out.print("\n");
   i++;

}

}


}

When the above code is executed, it produces the following results

Java program to create combined Pyramid pattern

 

 

Java program to print combined Pyramid number pattern

Combined Pyramid number pattern 1

Program 1

The Java program allows the user to enter the number of rows then it displays two combined straight pyramid number pattern according to the number of rows.

import java.util.Scanner;
class JointedPyramidwhile1{
public static void main(String args[]){
    int i,j;  //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();
System.out.print("\n");

i=1; 
while(i<=rows){  //parent while loop
    j=i; 
  while(j<=rows){
  System.out.print(" ");//print space
  j++;
  }
  j=1;
  while( j<=2*i-1){
  System.out.print(j);//print number
   j++;
  }
  j=2*i; 
   while(j<=2*rows-1){
  System.out.print(" ");//print space
  j++;
   }
   j=1;
  while( j<=2*i-1){
  System.out.print(j);//print number
  j++;
  }
  System.out.print("\n");//move to next line
i++;
}

}


}

When the above code is executed, it produces the following results

Java program to create combined Pyramid pattern

 

Combined Pyramid number pattern 2

Program 2

The Java program allows the user to enter the number of rows then it displays two combined upside-down pyramid number pattern according to the number of rows.

import java.util.Scanner;
class JointedPyramidwhile2{
public static void main(String args[]){
    int i,j;  //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();
System.out.print("\n");
i=1;
while( i<=rows){//parent while loop
    j=1; 
  while(j<i){
  System.out.print(" ");//print space
   j++;
  }
  j=1; 
  while(j<2*(rows-i+1)){
  System.out.print(j);//print number
   j++;
  }
  j=2; 
   while(j<2*i){
  System.out.print(" ");//print space
  j++;
   }
   j=1;
  while( j<2*(rows-i+1)){
  System.out.print(j);//print number
   j++;
  }
  System.out.print("\n");
   i++;

}

}


}

When the above code is executed, it produces the following results

Java program to create combined Pyramid pattern

 

 

Similar post

Java program to print combined Pyramid pattern

C program to print combined Pyramid pattern

C++ program to print combined Pyramid pattern

C program to print combined Pyramid pattern using while loop

C++ program to print combined Pyramid pattern using while loop

 

Suggested for you

For loop in Java language

Nested for loop in Java language

Operator n Java language

Data types and Variable in Java language

 

 

 

 

 

C++ program to print combined Pyramid pattern
C++ program to create combined Pyramid pattern using while loop
Java languageJava patternJava programsPattern