Write a program to calculate an area of a triangle accordingly
Answers
Hope it helps ^_^
This program asks the measure of sides as input instead of base and height
This program is in Java
_____________________________________
import java.util.Scanner;
public class Area_Of_Triangle{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
double a1, a2, a3, s, area;
System.out.print("Enter the first angle: ");
a1 = sc.nextDouble();
System.out.print("Enter the second angle: ");
a2 = sc.nextDouble();
System.out.print("Enter the third angle: ");
a3 = sc.nextDouble();
boolean truth = (a1+a2) > a3 && (a1 + a3) > a2 && (a2 + a3) > a1;
if (truth == true){
s = (a1 + a2 + a3)/2;
area = Math.sqrt(s * (s - a1) * (s - a2) * (s - a3));
System.out.println("Area of this triangle: " + area + " sq.unit");
}
else if (truth == false){
System.out.println("These sides cannot form a triangle *_*");
}
}
}
_____________________________________
Outputs:
(i)
Enter the first angle: 52
Enter the second angle: 48
Enter the third angle: 20
Area of this triangle: 480.0 sq.unit
(ii)
Enter the first angle: 5
Enter the second angle: 2
Enter the third angle: 3
These sides cannot form a triangle *_*