Explanation :
If n=5 then output will be
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15 .
Code:
import java.util.Scanner;public class Pattern24
{
public static void main( String args[])
{
System.out.print("Enter the number of rows:");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i,j,k;
k=1;
for (i=1;i<=n;i++)
{
for (j=n;j>=1;j--)
{
if(j > i)
System.out.printf(" ");
else
System.out.printf("%3d",k++);
}
System.out.printf("\n");
}
sc.close();
}
}
No comments:
Post a Comment