Assignemnt 92 and Heron Formula

Code

    /// Name: Xinting Chen
    /// Period: 7
    /// Program Name: Heron Formula
    /// File Name: HeronFormula.java
    /// Date Finished: 3/28/2016
  
        public class HeronFormula
        {
        	public static void main( String[] args )
        	{
        		double a;
        		
        		a = triangleArea(3, 3, 3);
        		System.out.println("A triangle with sides 3,3,3 has an area of " + a );
        
        		a = triangleArea(3, 4, 5);
        		System.out.println("A triangle with sides 3,4,5 has an area of " + a );
         
        		a = triangleArea(7, 8, 9);
        		System.out.println("A triangle with sides 7,8,9 has an area of " + a );
        
        		System.out.println("A triangle with sides 5,12,13 has an area of " + triangleArea(5, 12, 13) );
        		System.out.println("A triangle with sides 10,9,11 has an area of " + triangleArea(10, 9, 11) );
        		System.out.println("A triangle with sides 8,15,17 has an area of " + triangleArea(8, 15, 17) );
                System.out.println("A triangle with side 9,9,9 has an area of " + triangleArea(9, 9, 9) );
                //It wasnt difficult.
        	}
         
        	public static double triangleArea( int a, int b, int c )
        	{
        		// This code computes the area of a triangle which the length of its sides are a, b, and c.
        		double s, A;
        
        		s = (a+b+c) / 2.0;
        		A = Math.sqrt( s*(s-a)*(s-b)*(s-c) );
        
        		return A;
        		//After computing the area, "return" it.
        	}
        }
                //They both produce the same output.
                //The "no function one is 50, while the function one is 30.
                //It was easier to fix the one with a function.
         



    

Picture of the output

Assignment 92