TriangleArea

# TriangleArea - Scanner sc = new Scanner(System.in...

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

//******************************************************************** // 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;
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

## This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Ask a homework question - tutors are online