Write a program to print the following triangle.
*
**
****
*****
******
import java.util.Scanner;
class triangle{
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=n;i>=0;i--){
for(int j=i;j<n;j++){
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.