Sunday, October 16, 2011

Printing a pyramid pattern of digits #3

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

No comments:

Post a Comment