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

 OUTPUT:

javac Triangle.java
 
java Triangle 5
 
 1
 2  2
 3  3  3
 4  4  4  4
 5  5  5  5  5

 

Buy Head First Java

Best Book for Java

Beginner's Book