Monday, September 16, 2013

Java Program 010

Write a program DisplayPattern2.java, which accepts a number as argument and print the following output:

Ex. Input : 5

Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

public class DisplayPattern2
{
    public static void main(String args[])
    {
        int end = Integer.parseInt(args[0]);
        for(int i = 1; i <= end; i++)
        {
            for(int j = 1; j <= i; j++)
                System.out.print(j + " ");
            System.out.println("");
        }
    }
}

No comments:

Post a Comment