Write a program to print the following pyramid.
*
**
****
*****
******
import java.util.Scanner;
class pyramid{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the range of the pyramid : ");
int n = sc.nextInt();
for(int i=1;i<=n;i++){
for(int j=1;j<=n-i;j++){
System.out.print(" ");
}
for(int k=1;k<=2*i-1;k++){
System.out.print("* ");
}
System.out.println();
}
sc.close();
}
}
OUTPUT:
Enter the range of the pyramid :
5
*
**
****
*****
******
Comments
Post a Comment
Please do not enter any spam link in the comment box.