0% found this document useful (0 votes)
39 views1 page

Reverse Pyramid Star Pattern in Java

This Java program prints a reverse pyramid star pattern using nested while loops. It initializes the size of the pyramid and uses two inner loops to print spaces and stars for each row. The outer loop decrements to create the reverse effect until all rows are printed.

Uploaded by

hanukumar2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views1 page

Reverse Pyramid Star Pattern in Java

This Java program prints a reverse pyramid star pattern using nested while loops. It initializes the size of the pyramid and uses two inner loops to print spaces and stars for each row. The outer loop decrements to create the reverse effect until all rows are printed.

Uploaded by

hanukumar2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

// Java program to Print Reverse Pyramid Star Pattern

// Using While loop

// Importing input output classes


import [Link].*;

// Main class
class GFG {

// Main driver method


public static void main(String[] args)
{
// Declaring and initializing variable to
// Size of the pyramid
int number = 7;

int i = number, j;

// Nested while loops


// Outer loop

// Till condition holds true


while (i > 0) {
j = 0;

// Inner loop
// Condition check
while (j++ < number - i) {
// Print whitespaces
[Link](" ");
}

j = 0;

// Inner loop
// Condition check
while (j++ < (i * 2) - 1) {
// Print star
[Link]("*");
}

// By now, we reach end of execution for one row


// so next line
[Link]();

// Decrementing counter because we want to print


// reverse of pyramid
i--;
}
}
}

You might also like