-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPP2_10
More file actions
32 lines (25 loc) · 957 Bytes
/
PP2_10
File metadata and controls
32 lines (25 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.text.DecimalFormat;
import java.lang.Math;
import java.util.Scanner;
public class Triangle
{
public static void main (String[] args)
{
int a, b, c, discriminant;
double area, s;
//scanner
Scanner keyboard = new Scanner(System.in);
System.out.print("What is side a of the triangle? ");
a = keyboard.nextInt();
System.out.print("What is side b of the triangle? ");
b = keyboard.nextInt();
System.out.print("What is side c of the triangle? ");
c = keyboard.nextInt();
//three decimal places
DecimalFormat decimal = new DecimalFormat ("0.###");
//math
s = (double)(a + c + b)/2.0;
area = (double)(Math.sqrt(s* (s-a) * (s-b) * (s-c)));
System.out.println("The area of the triangle is " + decimal.format(area));
} //end main
} //end class triangle