Pyramid Star Pattern in Java

thumbnail

In this tutorial, you will learn to create pyramid star pattern in java.

Example 1:

package patternchallenge;
public class PatternChallenge {
    public static void main(String[] args) {
        pyramidPattern (5);
    }
 
    public static void pyramidPattern(int n){
        int space = n - 1;
        for (int j = 1; j<= n; j++){
            for (int i = 1; i<= space; i++){
                System.out.print(" ");
            }
            space--;
            for (int i = 1; i <= 2 * j - 1; i++){
                System.out.print("*");
            }
            System.out.println("");
        }
    }
}

The output will be:

    *
   ***
  *****
 *******
*********
Back To Top