Wednesday, 22 June 2016

Program to print a Number Pattern Type-23.

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 Pattern23
{
    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>=i;j--)
            {
                System.out.printf("%3d",k++);
            }
            System.out.printf("\n");
        }
        sc.close();
     }
}

No comments:

Post a Comment