Thursday, 13 June 2013

program for calculating area of triangle in java

import java.io.*;
class simple_area_triangle2
{
    public static void main(String args[])
    {
        try
        {
            int a,h,b;
            DataInputStream cin=new DataInputStream(System.in);
            System.out.println("Enter a hight to calculate area of triangle");
            h=Integer.parseInt(cin.readLine());
            System.out.println("Enter a breth to calculate area of triangle");
            b=Integer.parseInt(cin.readLine());
            a=h*b;
            System.out.println("area of triangle= "+h+" * "+b+" = "+a);
        }
        catch(Exception e)
        {
            System.out.println("Wrong data");
        }
    }
}

No comments: