How to print this pattern in java?
Attachments:
Answers
Answered by
2
Question:-
Write a program in Java to print the following pattern.
1 2 3 4 5
6 7 8 9
10 11 12
13 14
15
Program:-
import java.util.*;
class Pattern
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int n=sc.nextInt(), a=1;
for(int i=1;i<=n;i++)
{
for(int j=n;j>=i;j++)
System.out.print(a++ +" ");
System.out.println();
}
}
}
Similar questions