Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In geometry, Heron\'s (Hero\'s) formula, named after Heron of Alexandria, states

ID: 3622592 • Letter: I

Question

In geometry, Heron's (Hero's) formula, named after Heron of Alexandria, states that the area A of a triangle whose sides have lengths a, b, and c is the formula above.

where s is the semi-perimeter of the triangle:

Note that, as one of the properties of any triangle, the sum of the lengths of any two sides of a triangle must be greater than the third side.

Write a program that will receive interactively the values for a, b, and c. Your program should determine whether a, b, and c can be the length of the sides of a triangle given the above-mentioned property. If it does, determine the area of the triangle formed using Heron's formula; if not, output a message stating that a, b, and c do not form a triangle.

Explanation / Answer

please rate. import java.io.*; public class TriangleArea { public static void main(String args[]) throws IOException{ DataInputStream dis = new DataInputStream(System.in); System.out.println("---Area of triangle---"); System.out.println("Enter the sides of the triangle (each value in one line): "); double a = Double.parseDouble(dis.readLine()); double b = Double.parseDouble(dis.readLine()); double c = Double.parseDouble(dis.readLine()); if((a+b>c)||(a+c>b)||(b+c>a)){ double s = (a+b+c)/2; double area = Math.sqrt(s*(s+a)*(s+b)*(s+c)); System.out.println("Area is: "+area); } else{ System.out.println("Triangle sides incorrect."); } } }