Here is a Java program to find the area of an equilateral triangle. To find the area of an equilateral triangle, we need the length of any side of triangle. Before discussing about how to find the area of equilateral triangle, here is the brief summary of equilateral triangle.
- The length of all three sides of an equilateral triangle are equal.
- All three internal angles of equilateral triangle are equal and measures 60 degree.
The area of an equilateral triangle is the amount of two-dimensional space inside it. If we know the length of any side of equilateral triangle, then we can use following formulae to calculate it's area.
Area of Equilateral Triangle = (√ 3 /4)S2
Where, S is the length of each side of triangle.
Java Program to Find Area of an Equilateral Triangle
In this java program, we first take an integer input from user as the length of sides of equilateral triangle and store it in variable side. Then we calculate the area of given equilateral triangle using above mentioned formulae.
package com.tcc.java.programs; import java.util.Scanner; public class AreaOfEquilateralTriangle { public static void main(String[] args) { double side, area; Scanner scanner; scanner = new Scanner(System.in); // Take input from user System.out.println("Enter Length of Side of an Equilateral Triangle"); side = scanner.nextDouble(); area = Math.sqrt(3) / 4 * side * side; System.out.format("The Area of Equilateral Triangle = %.3f\n", area); } }Output
Enter Length of Side of an Equilateral Triangle 6 The Area of Equilateral Triangle = 15.588
Java Program to Find the Perimeter of Equilateral Triangle
Perimeter of equilateral triangle is the sum of the length of all three sides of the triangle. As we know, that all sides of equilateral triangles are equal, hence it's perimeter is equal to three times the length of any side of triangle.
package com.tcc.java.programs; import java.util.Scanner; public class PerimeterOfEquilateralTriangle { public static void main(String[] args) { double side, perimeter; Scanner scanner; scanner = new Scanner(System.in); // Take input from user System.out.println("Enter Length of Side of an Equilateral Triangle"); side = scanner.nextDouble(); /* Perimeter of equilateral triangle = 3 X Side */ perimeter = 3 * side; System.out.format("The Perimeter of Equilateral Triangle = %.3f\n", perimeter); } }Output
Enter Length of Side of an Equilateral Triangle 6 The Perimeter of Equilateral Triangle = 18.000
Recommended Posts