Write a java program to print the following pattern.
Here underscore means space.
Do write a proper program which is related to bluej environment
Answers
Answer:
import java.util.Scanner;
public class Num_Pattern
{
public static void main(String[] args)
{
// Create a new Scanner object
Scanner scanner = new Scanner(System.in);
// Get the number of rows from the user
System.out.println("Enter the number of rows to print the pattern ");
int rows = scanner.nextInt();
System.out.println("** Printing the pattern... **");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j);
}
for (int j= i*2 ; j < rows*2; j++)
{
System.out.print(" ");
}
for (int l = i; l >= 1; l--)
{
System.out.print(l);
}
System.out.println();
}
scanner.close();
}
}