tech Inverted Pyramid Star Pattern Java Program
Latest :

Inverted Pyramid Star Pattern Java Program

Java program to print Inverted Pyramid star pattern program – We have written below the print/draw Inverted 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 so that you can execute the below codes.

  • Using For Loop
  • Using While Loop
  • Using Do While Loop

Using For Loop

1) Read the value and store that value in the variable n.

2) To iterate through rows run the outer loop with the structure for(int i=n;i>0;i–).

3) To iterate through rows run the inner loops.

4) 1st inner loop prints space if i>0 && j<n-i.

5) 2nd inner loop prints character if i>0&&j<(i*2)-1

Output:

Using While Loop

1) Outer while loop iterate until i>0 is false.

2) 1st inner while loop prints space if the condition j++<n-i is true.

3) 2nd inner loop prints character if the condition j++<(i*2)-1 is true.

Output:

Using Do-While Loop

1) The outer do-while loop iterates until while(–i>0) is false.

2) The 1st inner loop prints space until the condition j++<n-i is false.

3) The 2nd inner loop prints the character until the condition j++<i*2-2 is false.

Output:

tech
x

Check Also

Merge Sort Java – Program 2 Ways | Sortings

Merge Sort Java –  Java program to implement merge sort using array & Buffered reader. ...