TriangleArea - Scanner sc = new Scanner(System.in);...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // TriangleArea.java Author: Lewis and Loftus // // Solution to Programming Project 2.10 //******************************************************************** / import java.util.Scanner; import java.text.DecimalFormat; i public class TriangleArea { //----------------------------------------------------------------- // Computes the area of a triangle given the length of each // side. Uses Heron's formula. //----------------------------------------------------------------- public static void main (String[] args) { double side1, side2, side3, temp, temp2, area;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Scanner sc = new Scanner(System.in); System.out.print ("Enter the length of side 1: "); side1 = Double.parseDouble(sc.nextLine()); System.out.print ("Enter the length of side 2: "); side2 = Double.parseDouble(sc.nextLine()); System.out.print ("Enter the length of side 3: "); side3 = Double.parseDouble(sc.nextLine()); temp = (side1 + side2 + side3) / 2; temp2 = temp * (temp-side1) * (temp-side2) * (temp-side3); area = Math.sqrt (temp2); DecimalFormat fmt = new DecimalFormat ("0.###"); System.out.println ("Area: " + fmt.format(area)); } }...
View Full Document

Ask a homework question - tutors are online