Showing posts with label numeric triangle. Show all posts
Showing posts with label numeric triangle. Show all posts

Thursday, 13 June 2013

print numeric triangle in java

import java.io.*;
class simple_print_numeric_trangle_type4
{
    public static void main(String args[])
    {
        try
        {
            int i,j,n;
            DataInputStream cin=new DataInputStream(System.in);
            System.out.println("enter the steps of trangle");
            n=Integer.parseInt(cin.readLine());

            for(i=n;i>=1;i--)
            {
                for(j=i;j>=1;j--)
                {
                    System.out.print(j);
                    System.out.print(" ");
                }
                System.out.println();

                if(i==5)
                System.out.print("  ");
                if(i==4)
                System.out.print("    ");
                if(i==3)
                System.out.print("      ");
                if(i==2)
                System.out.print("        ");
                if(i==1)
                System.out.print("          ");



            }
        }
        catch(Exception e)
        {
            System.out.println("wrong data");
        }
    }
}

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++;
        }
    }
}

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++;
        }
    }
}

print numeric triangle in java

/*
        print following trangle

        1
        1    2
        1    2    3
        1    2    3    4
        1    2    3    4    5    */

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

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

            while(c<=r)
            {
                System.out.print(c);
                System.out.print(" ");
                c++;
            }
            System.out.println();
            r++;
        }
    }
}

print numeric triangle in java

/*
        print following trangle

        1
        1    2
        1    2    3
        1    2    3    4
        1    2    3    4    5    */

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

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

            while(c<=r)
            {
                System.out.print(c);
                System.out.print(" ");
                c++;
            }
            System.out.println();
            r++;
        }
    }
}