Explanation :
If n=6 then output will be
666666
566666
456666
345666
234566
123456.
Code:
import java.util.Scanner;public class Pattern4
{
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;
for (i=n;i>=1;i--)
{
k = i;
for (j=1;j<=n;j++)
{
if(k <= n)
{
System.out.printf("%d",k);
} else
{
System.out.print(n);
}
k++;
}
System.out.printf("\n");
}
sc.close();
}
}
No comments:
Post a Comment