/ Published in: Java
Java Heron's formula
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import java.util.Scanner; public class HeronsFormula { double sidea = input.nextDouble(); double sideb = input.nextDouble(); double sidec = input.nextDouble(); System.out.println("The lengths of the sides of your triangle are: " + '\n' + sidea + '\n' + sideb + '\n' + sidec); System.out.println("The area of your triangle using Heron's Formula is: " + getArea(sidea,sideb,sidec)); } public static double getArea(double a, double b, double c) { //method calculates area double s = (a + b + c)/2.0; //s = perimeter/2 double x = ((s) * (s-a) * (s-b) * (s-c)); //herons formula return area; } }