# Posted By

acecengic on 12/17/14

# Statistics

Viewed 225 times
Favorited by 0 user(s)

# Heron's Formula

/ Published in: Java  Java Heron's formula

Copy this code and paste it in your HTML
`import java.util.Scanner; public class HeronsFormula {	public static void main(String[] args){		Scanner input = new Scanner(System.in);		System.out.print("Input the three sides");		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		System.out.println("s is: " + s);		double x = ((s) * (s-a) * (s-b) * (s-c)); //herons formula		double area = Math.sqrt(x); //math function to square the input from herons formula		return area;	}}` Subscribe to comments