Write a menu driven program to find the area of an Equilateral Triangle, an Isosceles Triangle
and a Scalene Triangle as per the user’s choice.
1. Equilateral Triangle= √3/4 s2
, s=side of an equilateral triangle
2. Isosceles Triangle= ¼ b*√4a2 – b
2
3. Scalene Triangle= √s(s-m) (s-n) (s-p), s=m+ n+ p
(where m, n and p are three sides of a scalene triangle)
Answers
formula of equilateral = root by 4 s2
Answer:
Explanation:
import java.io.*;
public class triangle
{
public static void main(String args[]) throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int c;
float a,s,p,q,r,b;
double area;
System.out.println("1.Area of equilateral triangle");
System.out.println("2.Area of isosceles triangle");
c=Integer.parseInt(in.readLine());
switch(c)
{
case 1:
System.out.println("Enter side of an equilateral triangle");
s=Float.parseFloat(in.readLine());
area=Math.sqrt(3*s*s)/4;
System.out.println("Area="+area);
break;
case 2:
System.out.println("Enter the side and base of isosceles triangle");
a=Float.parseFloat(in.readLine());
b=Float.parseFloat(in.readLine());
area=b/4*(Math.sqrt(4*a*a-b*b));
System.out.println("Area="+area);
break;
default:
System.out.println("Wrong choice ");
}
}
}
Hope it helps!