Wednesday, 22 June 2016

Program to print a Number Pattern Type-18.

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

Code:

import java.util.Scanner;
public class Pattern12
{
    public static void main(String args[])
    {
        System.out.print("Enter the number of Rows:");
        Scanner sc=new Scanner(System.in);
        int z=sc.nextInt();
        int i, k, x,j=5;
        for (i=1;i<=z;i++)
        {
            for (k=1;k<=j;k++)
            {
                System.out.printf(" ");
            }
            for (x=1;x<=i;x++)
            {
                System.out.print(i);
                System.out.printf(" ");
            }
            System.out.printf("\n");
            j=j-1;
        }
    }
}

No comments:

Post a Comment