Pyramid Pattern in Java Using For Loop

Pyramid pattern in java. Java is used to enforce the right side pattern. Only an asterisk can be printed on the right side of a java application using this program. In the creation of the Java programming language, the pattern is slightly to the right. A 90° angle can be created by cutting a square corner in half or quartering a circle.

For Loop Statement in Java

The “for” loop in Java is an entry-controlled loop that allows a user to iteratively run a block of statement(s) for a fixed number of times. The number of iterations is determined by the test condition specified within the “for” loop. 

The Java “for” loop is one of the simplest Java loops to grasp. A “For” Loop is used to iterate over a specified block of code a predetermined number of times. When the number of iterations is known before entering the loop, for loops are commonly employed. For loops are shorthand for while loops in that they increase and test a loop variable.

public class Main 
{ 
public static void main(String[] args) 
{ 
int n=5; 
for (int i= 0; i<= n; i++) 
{ 
for (int j=1; j<=n-i; j++) 
{ 
System.out.print(" "); 
} 
for (int k=0;k<=i;k++) 
{ 
System.out.print("*"); 
} 
System.out.println(""); 
} 
} 
} 

 

Output:

     * 

    ** 

   *** 

  ****  

 *****  

******