Thursday, October 27, 2011

Printing a pyramid pattern of digits #11

//This java program accepts a number of user
//which tells the program that how many lines
//of the pattern will be printed.
/*Sample Input :6
Sample Output :
1
22
333
4444
55555
666666   */


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

//Author: Mayank Rajoria

No comments:

Post a Comment