How to form a Pyramid Pattern

 Step 1

        Outer Loop (for loop with variable i):

        This loop controls the number of rows in the pyramid. It iterates from 1 to the specified number of              rows (rows).

       


Step 2( Inner Loop 1 (for loop with variable j):


        This loop is responsible for printing spaces before the stars on each row.

        It prints a number of spaces equal to rows - i. As i increases, fewer spaces are printed for each row,            creating a left-align effect.

       


Step 3 (Inner Loop 2 (for loop with variable k)

        This loop prints the stars on each row.

        It prints a number of stars equal to 2 * i - 1. The number of stars increases as i increases, creating            the   pyramid shape.



Step 4        System.out.println();

       This line is used to move to the next line after printing spaces and stars for each row. It ensures that         the next row starts on a new line.

        The combined effect of the outer and inner loops is to print a pyramid pattern made of stars, where         each row has spaces and stars in the appropriate positions to create the pyramid shape. Adjust the           value of the rows variable to change the size of the pyramid.*/





Comments

Popular posts from this blog

Swabbing Tow no's

"Java Programming: Arrays, Methods, and Stream API"

Reversing the String ; Doubling Each Letter