Codeforcoding

Java program to print combined Pyramid pattern

Java program to print combined Pyramid pattern

In this tutorial, we will discuss the concept of the Java program to print 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 for loop  in Java language

Program to display combined Pyramid star pattern

Combined Pyramid star pattern 1

Program 1

import java.util.Scanner;
class JointedPyramid1{
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(); //Takes input from the user for number of rows
System.out.print("\n");
for(i=1; i<=rows; i++){
  for(j=i; j<=rows; j++){
  System.out.print(" ");//print space
  }
  for(j=1; j<=2*i-1; j++){
  System.out.print("*");//print star
  }
   for(j=2*i; j<=2*rows-1; j++){
  System.out.print(" ");//print space
   }
  for(j=1; j<=2*i-1; j++){
  System.out.print("*");
  }
  System.out.print("\n");

}

}


}

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

Java program to print jointed Pyramid pattern
jointed Pyramid pattern 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.

Combined Pyramid star pattern 2

Program 2

import java.util.Scanner;
class JointedPyramid2{
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(); //Takes input from the user for number of rows
System.out.print("\n");
for(i=1; i<=rows; i++){
  for(j=1; j<i; j++){
  System.out.print(" ");//print space
  }
  for(j=1; j<2*(rows-i+1); j++){
  System.out.print("*");/print star
  }
   for(j=2; j<2*i; j++){
  System.out.print(" ");//print space
   }
  for(j=1; j<2*(rows-i+1); j++){
  System.out.print("*");/print star
  }
  System.out.print("\n");

}

}


}

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

Jointed Pyramid pattern 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.

 

Program to display combined Pyramid number pattern

Combined Pyramid number pattern 1

Program 1

import java.util.Scanner;
class JointedPyramid1{
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(); //Takes input from the user for number of rows
System.out.print("\n");
for(i=1; i<=rows; i++){
  for(j=i; j<=rows; j++){
  System.out.print(" ");//print space
  }
  for(j=1; j<=2*i-1; j++){
  System.out.print(j);//print number
  }
   for(j=2*i; j<=2*rows-1; j++){
  System.out.print(" ");//print space
   }
  for(j=1; j<=2*i-1; j++){
  System.out.print(j);//print number
  }
  System.out.print("\n");

}

}


}

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

Jointed Pyramid pattern 3

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.

 

Combined Pyramid number pattern 2

Program 2

import java.util.Scanner;
class JointedPyramid2{
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(); //Takes input from the user for number of rows
System.out.print("\n");
for(i=1; i<=rows; i++){
  for(j=1; j<i; j++){
  System.out.print(" ");//print space
  }
  for(j=1; j<2*(rows-i+1); j++){
  System.out.print(j);  //print number
  }
   for(j=2; j<2*i; j++){
  System.out.print(" ");//print space
   }
  for(j=1; j<2*(rows-i+1); j++){
  System.out.print(j);//print number
  }
  System.out.print("\n");

}

}


}

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

Jointed Pyramid pattern 4

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.

 

Similar post

C program to the combined Pyramid pattern

C++ program to the combined Pyramid pattern

 

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

class and main method in Java language

 

C program to print combined Pyramid pattern
C++ program to print combined Pyramid pattern
Exit mobile version