Pyramid Pattern Printing in Java

A pyramid pattern is a geometric arrangement of characters, often represented by asterisks (*), forming the shape of an upward-pointing pyramid. Each row of the pyramid contains a specific number of characters, with the number increasing from top to bottom. It is a common programming exercise to practice nested loops and pattern printing.

Here is the Java program for it:

package com.javacodepoint.patterns;

public class PyramidPattern {
	public static void main(String[] args) {
		int rows = 5;

		for (int i = 1; i <= rows; i++) {
			for (int j = 1; j <= rows - i; j++) {
				System.out.print(" ");
			}

			for (int k = 1; k <= 2 * i - 1; k++) {
				System.out.print("*");
			}

			System.out.println();
		}
	}
}

OUTPUT:

Pyramid Pattern Printing program in Java

See also: Top 30-star pattern programs in Java.

Java logical programs list


Java Basic Programs

Java String Programs

Java Programs based on the Collection Framework

Leave a Reply

Your email address will not be published. Required fields are marked *