Wednesday, 22 June 2016

Program to print a Number Pattern Type-19.

Explanation :
If n=6 then output will be
          1
        1 2
      1 2 3
    1 2 3 4
  1 2 3 4 5
1 2 3 4 5 6 .

Code:

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

No comments:

Post a Comment