Explanation :
If n=6 then output will be
1
21
321
4321
54321
654321.
Code:
import java.util.Scanner;public class Pattern11
{
public static void main( String arg[])
{
System.out.print("Enter the number of rows:");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for (int i=1;i<=n;i++)
{
for (int j=n;j>=1;j--)
{
if(j<=i)
System.out.printf("%d",j);
else
System.out.printf(" ");
}
System.out.printf("\n");
}
sc.close();
}
}
No comments:
Post a Comment