area of scalene triangle in java

Solutions on MaxInterview for area of scalene triangle in java by the best coders in the world

showing results for - "area of scalene triangle in java"
Pietro
15 Jul 2017
1import java.util.Scanner;
2
3public class Main {
4
5    public static void main(String[] args) {
6
7        // area of scalene triangle 
8
9        Scanner scanner = new Scanner(System.in);
10
11        System.out.print("Enter the sides (a,b,c): ");
12        float side1 = scanner.nextFloat(), side2 = scanner.nextFloat(), side3 = scanner.nextFloat();
13
14        float semiPerimeter = (side1 + side2 + side3) / 2;
15
16        double area = Math.sqrt( semiPerimeter * (semiPerimeter-side1) * (semiPerimeter-side2) * (semiPerimeter-side3) );
17
18        System.out.printf("The area is %.2f",area);
19    }
20}