Display integrated pyramid star pattern in Java using while loop
Display integrated pyramid star pattern in Java using while loop
In this tutorial, we will discuss a concept of Display integrated pyramid star pattern in Java using while loop.
In Java language, we can use for loop , while loopand do-while loopto display different number (binary, decimal), alphabets or star pattern programs.
In this article, we are going to learn how toDisplay double pyramid star pattern using while loop in Java programming language
Integrated pyramid Star 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 for number of rows
i=1;
while(i<=row){
j=i;
while(j<=row){ //print upper part of pattern
System.out.print("*");
j++;
}
i++;
System.out.print("\n");
}
i=row-1;
while(i>=1){ //print lower part of pattern
j=i;
while(j<=row){
System.out.print("*");
j++;
}
i--;
System.out.print("\n");
}
}
}
When the above code is executed, it produces the following results
pyramid star pattern 1
Integrated pyramid Star 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 for number of rows
i=1;
while(i<=row){
j=1;
while(j=1){ //print lower part of pattern
j=1;
while(j
When the above code is executed, it produces the following results
pyramid star pattern 2
Integrated pyramid Star pattern 3
Program 3
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 for number of rows
i=1;
while(i<=row){
j=1;
while(j<=i){ //print upper part of pattern
System.out.print(" ");
j++;
}
j=i;
while(j<=row){
System.out.print("*"+" ");
j++;
}
i++;
System.out.print("\n");
}
i=row-1;
while(i>=1){ //print lower part of pattern
j=1;
while(j<=i){
System.out.print(" ");
j++;
}
j=i;
while(j<=row){
System.out.print("*"+" ");
j++;
}
i--;
System.out.print("\n");
}
}
}
When the above code is executed, it produces the following results
pyramid star pattern 3
Integrated pyramid Star pattern 4
Program 4
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 for number of rows
i=1;
while(i<=row){
j=1;
while(j<=row-i){ //print upper part of pattern
System.out.print(" ");
j++;
}
j=1;
while(j<=i){
System.out.print("*"+" ");
j++;
}
i++;
System.out.print("\n");
}
i=1;
while(i<=row-1){ //print lower part of pattern
j=1;
while(j<=i){
System.out.print(" ");
j++;
}
j=1;
while(j<=row-i){
System.out.print("*"+" ");
j++;
}
i++;
System.out.print("\n");
}
}
}
When the above code is executed, it produces the following results
pyramid star pattern 4
integrated pyramid Star pattern 5
Program 5
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();
i=1;
while(i<=rows){
for(j=1; j<=i; j++){ //print upper part of pattern
System.out.print("*");
}
j=i*2;
while(j=1){
System.out.print("*");
k--;
}
System.out.print("\n");
i++;
}
}
}
When the above code is executed, it produces the following results
pyramid star pattern 5
integrated pyramid Star pattern 6
Program 6
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();
i=rows;
while(i>=1){ //parent while loop
j=rows;
while(j>=1+rows-i){ //print upper part of pattern
System.out.print("*");
j--;
}
j=i*2;
while(j
When the above code is executed, it produces the following results