In: Computer Science
Write a program that prompts the user to enter an integer from 1 to 15 and displays a
pyramid, as shown in the following sample run:
here............THE PYRAMID HAS TO BE THIS SHAPE
AND IT IS DONE IN JAVA PLEASE
7 6 5 4 3 2 1 2 3 4 5 6 7
6 5 4 3 2 1 2 3 4 5 6
5 4 3 2 1 2 3 4 5
4 3 2 1 2 3 4
3 2 1 2 3
2 1 2
1
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer
from 1 to 15: ");
int n = sc.nextInt();
while(n<1||n>15)
{
System.out.print("Enter an integer
from 1 to 15: ");
n = sc.nextInt();
}
for(int i=n;i>=1;i--)
{
for(int j=i;j>=1;j--)
{
System.out.print(j+" ");
}
for(int j=2;j<=i;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}