Thursday 13 June 2013

program for numeric triangle in java

/*
        print following trangle

        1
        2    3
        4    5    6
        7    8    9    10
        11    12    13    14    15    */

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

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

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

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

No comments:

Post a Comment