Tuesday, October 4, 2011

Printing a pyramid pattern of digits #1

//This java program accepts a number of user
//which tells the program that how many lines
//of the pattern will be printed.
//Sample Input :5
//Sample Output :
//1 
//2  3 
//4  5  6 
//7  8  9  10 
//11  12  13  14  15 
import java.util.*;
class pattern
{
public static void main()
{
    int i,j,k;
    System.out.println("Enter the number of lines you want");
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    k=1;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=i;j++)
        {
            System.out.print(k+"  ");
            k++;
        }
        System.out.println();
    }
}
}
Author : Mayank Rajoria

No comments:

Post a Comment