Wednesday, 22 June 2016

Program to print a Number Pattern Type-17.

Explanation :
If n=6 then output will be
111111
22222
3333
444
55
6.

Code:

import java.util.Scanner;
public class Pattern17
{
    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;
        for (i=1;i<=n;i++)
        {
            for (j=n;j>=i;j--)
            {
                System.out.printf("%d",i);
            }
            System.out.printf("\n");
        }
        sc.close();
     }
}

No comments:

Post a Comment