Inverted Pyramid Pattern

Inverted Pyramid pattern is another popular pattern. Its logic is similar to Inverted Mirrored Right Angle Triangle Pattern. Let us see the logic to create an inverted pyramid easily.

public class Tech4Humans {
	public static void main(String[] args) {

		// length of triangle
		int size = 5;

		// Logic is similar to Inverted Mirrored Right Angle Triangle Pattern
		for (int i = 0; i < size; i++) {
			for (int j = 0; j < i; j++) {
				System.out.print(" ");
			}
			for (int k = 0; k < (size - i); k++) {
				System.out.print("* ");
			}
			System.out.println();
		}

	}
}

Output

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

Understand the above code’s logic and try to create your own pyramid without any help. To help you understand the logic better visit  RIGHT WAY TO DEBUG CODE USING PEN AND PAPER.

Leave a Comment