In this tutorial, we are going to write a Java program to print a star pattern in a pyramid shape in java Programming with practical program code and step-by-step full complete explanation.
Java program to print a star pattern in a pyramid shape.
class Pattern5 { public static void main(String args[]) { int sp=20; for(int i=1;i<=5;i++) { for(int k=1;k<=sp;k++) { System.out.print(" "); } sp--; for(int j=1;j<=i;j++) { System.out.print("* "); } System.out.println(); } } }
Output
* * * * * * * * * * * * * * *