Wednesday, 22 June 2016

Program to print a Number Pattern Type-5.

Explanation :
If n=6 then output will be
1
12
123
1234
12345
123456.

Code:

import java.util.Scanner;
public class Pattern5
{
    public static void main( String args[])
    {
        System.out.print("Enter the number of rows:");
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for(int i = 1; i <= n ; i++)
        {
            for(int j = 1; j <= i ; j++)
            {
                System.out.print(j);
            }
            System.out.println();
        }
        sc.close();
    }
}

No comments:

Post a Comment