// Scott DeRuiter 9/22/2002 // Heron.java // Asks for the side lengths of a triangle, then // calculates the area using Heron's formula. // 7/15/2011 - Greenstein: Changed TextReader to Scanner, added import Math import java.util.Scanner; import java.lang.Math; public class Heron { public static void main ( String [] args ) { double side1, side2, side3, semiperim, area; Scanner keyboard = new Scanner ( System.in ); System.out.print ( "\n\nEnter the length of the first side -> " ); side1 = keyboard.nextDouble ( ); System.out.print ( "\n\nEnter the length of the second side -> " ); side2 = keyboard.nextDouble ( ); System.out.print ( "\n\nEnter the length of the third side -> " ); side3 = keyboard.nextDouble ( ); semiperim = ( side1 + side2 + side3 ) / 2.0; area = Math.sqrt(semiperim * (semiperim - side1) * (semiperim - side2) * (semiperim - side3)); System.out.println ( "\n\nHere is the information for your triangle:" ); System.out.println ( "side1 : " + Format.right ( side1, 12, 3) ); System.out.println ( "side2 : " + Format.right ( side2, 12, 3 ) ); System.out.println ( "side3 : " + Format.right ( side3, 12, 3 ) ); System.out.println ( "area : " + Format.right ( area, 12, 3 ) ); } }