star pattern

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 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 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<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 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<rows*2){      //print lower part of pattern
  System.out.print(" ");
   j++;
}

k=i;
while( k>=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<rows*2-1){     
  System.out.print(" ");
  j++;
  
    }

    k=1+rows-i;
    while( k<=rows){   //print lower part of pattern
    if(k!=1)
  System.out.print("*");
 k++;
  
   }

  System.out.print("\n");
  i--;

}
}
}

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

Pyramid star pattern 6

Similar post

Display integrated pyramid star pattern in C++ using while loop

Display integrated pyramid star pattern in C using while loop

C code to print double pyramid star pattern

Java code to print double pyramid star pattern

C++ code to print double pyramid star pattern

 

Suggested for you

Data types and variable in Java language

While loop in  Java  language

Nested while loop in Java language

Display integrated pyramid star pattern in C using while loop
Java program to Integrated triangle patterns using for loop
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

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

3 days ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago