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 *


Output

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

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


Output

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

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


Output

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


Output

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 *


Output

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

Previous Post Next Post