Nested For Loop to Print the Pyramid and Pattern in Java

In this program, you'll learn to create pyramid, half pyramid, inverted pyramid in Java. To print patterns of numbers and stars (*) in Java Programming, you have to use two loops, first is outer loop and the second is inner loop. The outer loop is responsible for rows and the inner loop is responsible for columns.

Example 1: Java program to print half pyramid using *


When you run the program, the output will be:

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

Example 2: Java program to print upper half pyramid using *


When you run the program, the output will be:

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


Example 3: Java program to print half pyramid a using numbers


When you run the program, the output will be:

1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 

Example 4: Java program to print half pyramid using alphabets


When you run the program, the output will be:

A 
B B 
C C C 
D D D D 
E E E E E 
F F F F F F 

Example 5: Java program to print full pyramid using *


When you run the program, the output will be:

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

Previous Post Next Post