Write a program in java to input a positive integer and print the numeric pattern using the numbers from 1 to the inputted number in form of an Hourglass.
Answers
Answer:-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
★ Program to print Hourglass pattern in Java:-
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
★
import java.util.*;
public class Hourglass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows:");
//
int r = sc.nextInt();
System.out.println("The Pattern is::");
//
for (int a = 1; a <= r; a++)
{
//
for (int b = 1; b < a; b++)
{
System.out.print(" ");
}
//
for (int b = a; b <= r; b++)
{
System.out.print(b+" ");
}
System.out.println();
}
//
for (int a = r-1; a >= 1; a--)
{
//
for (int b = 1; b < a; b++)
{
System.out.print(" ");
}
//
for (int b = a; b <= r; b++)
{
System.out.print(b+" ");
}
System.out.println();
}
sc.close();
}
}
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
★ Refer to attachment for Output.
★ Input value in the above Output is 10.