Latest :

Java Pyramid Star Pattern Program | Patterns

Java program to print Pyramid star pattern program. We have written the below print/draw Pyramid asterisk/star pattern program in four different ways with sample example and output, check it out. At the end of the program, we have added compiler such that you can execute the below codes.

  • Print Pyramid Star Pattern – Using For Loop
  • Print – Using While Loop
  • Print – Using Do While Loop

Using For Loop

1) The outer for loop iterates until the condition i<=n is false. It represents rows.

2) 1st inner for loop will display space until j<n-i is false, 2nd inner loop display the character until the condition j<(i*2)-1 is false. These two loops represent the column.


Using While Loop

1) The outer while loop executes the statements until the condition i<n is false.

2) The 1st inner while loop will display space until j++<n-i is false. The 2nd inner loop will display character until j++<(i*2)-1 is false.


Using Do-While Loop

1) The outer do-while loop will execute the code until ++i<n is false.

2) The 1st inner do-while loop will prints space until j++<(n-i-1)is false, the 2nd inner loop will prints character until the condition j++<i*2-2 is false



Check Also

Java Program to Add Two Matrices – 4 Ways | Programs

Java program to add two matrices – The following Java Code will let you know ...