Pyramid star pattern

Pyramid star pattern

To print the Pyramid star pattern we need two loop. first is outer loop and second is inner loop.

first loop that is the outer loop works on the row or line and the another loop that is inner loop works on the column mean how many start you want to put in the single line.so here we need to now proper working of the loop that we can easily make a desired pattern.

Now we will discuss all possible star pattern using java. 

1. Write a Program to print the following pattern.

* 
* *
* * *
* * * *
* * * * *

Working

Step 1- first you need to initialize two variable for loop.

Step 2- the first loop  for the row.

Step 3-  the second loop work for the column.

Step 4- now print the *.

Step 5- now out side of loop, put new line.

Step 5- stop.

2. Write a program to print the following pattern

* 
* * *
* * * * *
* * * * * * *
* * * * * * * * *

3. Write a program to print the following pattern

        * 
* *
* * *
* * * *
* * * * *

4. Write the code to print the following patter

                * 
          * * *
       * * * * *
    * * * * * * *
* * * * * * * * *

5. Write the code to print the following pattern.

    *
   ***
  *****
 *******
*********

4 comments on “Pyramid star pattern”


  • Vyas

    For * pyramid printing
    #include
    using namespace std;
    int main()
    {
    int i,j,k=0,row=5;

    for (i=1;i<=row;i++)
    {

    for(j=1;j<=row-i;j++)
    printf(" ");
    for(k=1;k<=(2*i-1);k++)
    printf("*");
    printf("\n");
    }
    return 0;
    }


  • Nishant

    QUESTION:5 Solutions
    public class Star
    {
    public static void main(String args[])
    {
    int i,k=9,p=1;
    for(i=0;i<5;i++) //For the row
    {
    for(int z=0;z<k;z++) // for the spaces in a row
    System.out.print(" ");

    k= k-1;
    for(int j=0;j<p;j++) // for printing the *
    {
    System.out.print("*");
    }
    p = p + 2;

    System.out.println();
    }
    }
    }


    • HelpPrepInsta

      Thank you for your appreciation…. We also want you to know that we are happy to help you and serve you better!!!