Return to Snippet

Revision: 68245
at December 17, 2014 15:44 by acecengic


Initial Code
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;
	}
}

Initial URL


Initial Description
Java Heron's formula

Initial Title
Heron's Formula

Initial Tags
java

Initial Language
Java