Untitled

 avatar
unknown
java
3 years ago
905 B
4
Indexable
import java.util.*;
public class heronsformula {
    
    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        double s1, s2, s3, area, S;
        System.out.println("Find the area of any triangle using Heron's Formula:");
        System.out.println("----------------------------------------------------");
        System.out.printf("Input the length of 1st side of the triangle: ");
        s1 = input.nextDouble();
        System.out.printf("Input the length of 2nd side of the triangle: ");
        s2 = input.nextDouble();
        System.out.printf("Input the length of 3rd side of the triangle: ");
        s3 = input.nextDouble();
        
        S = (s1 + s2 + s3) / 2;
        area = Math.sqrt(S*(S-s1)*(S-s2)*(S-s3));
        
        System.out.println("The area of the triangle is: " 
                + String.format("%.4f", area ));
    }
    
}