area of isosceles triangle in java

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

showing results for - "area of isosceles triangle in java"
Atlanta
22 Jan 2019
1import java.util.Scanner;
2
3public class Main {
4
5    public static void main(String[] args) {
6
7        // area of isosceles triangle
8
9        Scanner scanner = new Scanner(System.in);
10
11        System.out.print("Enter length of same side: ");
12        float equalLength = scanner.nextFloat();
13
14        System.out.print("Enter length of the other side: ");
15        float base = scanner.nextFloat();
16
17        float height = (float) Math.sqrt(Math.pow(equalLength,2) - (base / 4) );
18
19        double area = 0.5f * base * height;
20
21        System.out.printf("The area is %.2f",area);
22    }
23}
Hanna
01 Nov 2019
1import java.util.Scanner;
2public class AreaOfIsoscelesTriangle
3{
4   public static void main(String[] args)
5   {
6      Scanner sc = new Scanner(System.in);
7      System.out.println("Please enter length of same sided: ");
8      double a = sc.nextDouble();
9      System.out.println("Please enter side2 of isosceles triangle: ");
10      double b = sc.nextDouble();
11      double area = (b/4) * Math.sqrt((4 * a * a) - (b * b));
12      System.out.println("Area of isosceles triangle is: " + area);
13      sc.close();
14   }
15}