Blonk

Untitled

Mar 10th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. public class Main
  2. {
  3.     public static void main( String[] args )
  4.     {
  5.         double a;
  6.  
  7.         a = triangleArea(3, 3, 3);
  8.         System.out.println("A triangle with sides 3,3,3 has an area of " + a );
  9.  
  10.         a = triangleArea(3, 4, 5);
  11.         System.out.println("A triangle with sides 3,4,5 has an area of " + a );
  12.  
  13.         a = triangleArea(7, 8, 9);
  14.         System.out.println("A triangle with sides 7,8,9 has an area of " + a );
  15.  
  16.         System.out.println("A triangle with sides 5,12,13 has an area of " + triangleArea(5, 12, 13) );
  17.         System.out.println("A triangle with sides 10,9,11 has an area of " + triangleArea(10, 9, 11) );
  18.         System.out.println("A triangle with sides 8,15,17 has an area of " + triangleArea(8, 15, 17) );
  19.     }
  20.  
  21.     public static double triangleArea( int a, int b, int c )
  22.     {
  23.         // the code in this function computes the area of a triangle whose sides have lengths a, b, and c
  24.         double s, A;
  25.  
  26.         s = (a+b+c) / 2;
  27.         A = Math.sqrt( s*(s-a)*(s-b)*(s-c) );
  28.  
  29.         return A;
  30.         // ^ after computing the area, "return" it
  31.     }
  32. }
Add Comment
Please, Sign In to add comment