Saturday 26 March 2016

To Check is Triangle or Not

Code:


import java.util.*;
class triangle
{
    public static void main(String[] args) {
        int a,b,c;
        double area;
        System.out.println("Let a,b,c are the three sides of triangle");
        Scanner in=new Scanner(System.in);
        System.out.print("\nEnter a: ");
        a=in.nextInt();
        System.out.print("Enter b: ");
        b=in.nextInt();
        System.out.print("Enter c: ");
        c=in.nextInt();
        if ((a>b)||(b>c))
        {
            System.out.print("Unacceptable values");
        }
        else if (a+b<=c)
        {
            System.out.print("Length do not represents triangle sides");
        }
        else
        {
            System.out.print("Length represents triangle sides\n");
            area=0.5*a*b;
            System.out.print("Then the area of the triangle is: "+area);
        }
    }
}

Output:


No comments:

Post a Comment