Thursday 13 June 2013

program for numeric triangle in java

/*
        print following trangle

        2
        4    6
        8    10    12
        14    16    18    20
        22    24    26    28    30    */

import java.io.*;
class simple_print_numeric_trangle_type3
{
    public static void main(String args[])
    {
        int r=1,c,i=2;

        while(r<=5)
        {
            c=1;

            while(c<=r)
            {
                System.out.print(i);
                System.out.print("\t");
                i=i+2;
                c++;

            }
            System.out.println();
            r++;
        }
    }
}

No comments: