Sunday, December 29, 2013

Can form a triangle? Normal, Isosceles, Equilateral Trangle

// Write a program to accept
// the three sides of a triangle
// from command line arguments.
// Then decide these can form
// a triangle or not. Then
// distinguish normal triangle,
// isosceles triangle or
// equilateral triangle

class triangle
{
  public static void main(String args[])
  {
    int a,b,c;
    if(args.length==3)
    {
        a=Integer.parseInt(args[0]);
        b=Integer.parseInt(args[1]);
        c=Integer.parseInt(args[2]);
        if(a+b>c && a+c>b && b+c>a)
        {
           if(a==b && a==c)
              System.out.println("Equilateral Triangle");
           else
              if(a==b || b==c || a==c)
                 System.out.println("Isosceles Triangle");
              else
                 System.out.println("Normal Triangle");
        }
        else
           System.out.println("Can't form a triangle");
    }
    else
        System.out.println("java triangle ##  ##  ##");
  }
}

No comments:

Post a Comment