Write a program in Java:
Answers
Write a program in Java:
Explanation:
Program In Java to print Pattern
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//input number of rows
System.out.println("Enter number of rows: ");
int rows = sc.nextInt();
System.out.println("Print Pattern....!!!");
for (int i = rows; i >= 1; i--)
{
for (int j = i; j >= 1; j--)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
Output
Enter number of rows:
8
Print Pattern....!!!
8 7 6 5 4 3 2 1
7 6 5 4 3 2 1
6 5 4 3 2 1
5 4 3 2 1
4 3 2 1
3 2 1
2 1
1
Here is your code.