Thursday, October 27, 2011

Printing a pyramid pattern of digits #10

//This java program accepts a number of user
//which tells the program that how many lines
//of the pattern will be printed.
/*Sample Input :7
Sample Output :

1234567
  123456
    12345
      1234
        123
          12
            1  */

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 i,j,k=1;
    for(i=n;i>=1;i--,k++)
    {
        for(j=1;j<k;j++)
        {
            System.out.print(" ");
        }
        for(j=1;j<=i;j++)
        {
            System.out.print(j);
        }
        System.out.println();
    }
}
}

//Author : Mayank Rajoria

No comments:

Post a Comment