-
Notifications
You must be signed in to change notification settings - Fork 8
/
Triangle1.java
26 lines (25 loc) · 1.19 KB
/
Triangle1.java
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
//*******************************************************
// Triangle1.java.
// Calculation of area and perimeter of a triangle.
// Author: liron mizrahi
//*******************************************************
import java.util.Scanner;
public class Triangle1
{
public static void main (String [] args)
{
Scanner scan = new Scanner (System.in); // Create Reader
System.out.println("This program calculate the area and the perimeter of a given triangle. ");
System.out.print("Enter the three lengths of the triangle's sides"); // Ask for input
int a = scan.nextInt(); // Read value from user
int b = scan.nextInt();
int c = scan.nextInt();
// The calculation according to the Heron formula for a triangular area
double s = (a + b + c) / 2.0;
double area = Math.sqrt(s * (s-a) * (s-b) * (s-c));
int perimeter = a + b + c;
System.out.println("The lengths of the triangle sides are: " + a + ", " + b + ", " + c + ".");
System.out.println("The perimeter of the triangle is: " + perimeter);
System.out.println("The area of the triangle is: " + area);
}// end of method main
}// end of class Triangle1