area of equilateral triangle in java

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

showing results for - "area of equilateral triangle in java"
Esteban
25 Jun 2017
1import java.util.Scanner;
2public class AreaOfEquilateral
3{
4   public static void main(String[] args)
5   {
6      Scanner sc = new Scanner(System.in);
7      System.out.println("Please enter the side of equilateral triangle: ");
8      double side = sc.nextDouble();
9      double area = (Math.sqrt(3)/4) * (side * side);
10      System.out.println("Area of equilateral triangle is: " + area);
11      sc.close();
12   }
13}
Hanna
14 Apr 2018
1import java.util.Scanner;
2
3public class Main {
4
5    public static void main(String[] args) {
6
7        // area of equilateral triangle
8
9        Scanner scanner = new Scanner(System.in);
10
11        System.out.print("Enter the equal length: ");
12        float equalLength = scanner.nextFloat();
13
14        double area = (Math.sqrt(3) / 4) * Math.pow(equalLength,2);
15
16        System.out.printf("The area is %.2f",area);
17    }
18}