Half Pyramid Pattern in Java of Stars using For loop
ADVERTISEMENTS
Half pyramid pattern in java of stars using for loop. In this article, you will learn how to draw the half pyramid pattern in java of stars using for loop.
Source Code
// Half Pyramid Pattern in Java of Stars using For loop
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int r = 0, i, j;
// r - denotes the number of rows
System.out.println("-----To print the half pyramid enter the number of rows-----");
r = in.nextInt();
System.out.print("\n");
for (i = 1; i <= r; ++i) {
for (j = 1; j <= i; ++j)
System.out.print("* ");
System.out.print("\n");
}
}
}
Output
-----To print the half pyramid enter the number of rows-----
10
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *