In this article we will show you, How to write Java Program to find Area of Equilateral Triangle, Perimeter, Semi Perimeter and Altitude of Equilateral Triangle with example. Before we step into practical example, Let see the definitions and formulas behind the Area of an Equilateral Triangle.

## Area of an Equilateral Triangle

The Equilateral Triangle is a triangle of equal sides and all angles are equal to 60 degrees.

- If we know the side of an Equilateral Triangle then, we can calculate the area of an Equilateral Triangle using below formula. Area = (√3)/4 * s² (S = Any side of the Equilateral Triangle)
- Perimeter is the distance around the edges. We can calculate perimeter using math formula: Perimeter = 3s
- We can calculate Semi Perimeter of an Equilateral Triangle using the formula: 3s/2 or we can simply say Perimeter/2. Here s is side of an Equilateral Triangle
- We can calculate Altitude of an Equilateral Triangle using the formula: (√3)/2 * s

## Java Program to find Area of Equilateral Triangle

This Java program allows the user to enter length of any one side of an Equilateral Triangle. Using this value we will calculate the Area, Perimeter, Semi Perimeter, Altitude of the Equilateral Triangle.

**JAVA CODE**

// Java Program to find Area of Equilateral Triangle package Area; import java.util.Scanner; public class AreaOfEquilateralTriangle { private static Scanner sc; public static void main(String[] args) { double side, Area, Perimeter, Semi, Altitude; sc = new Scanner(System.in); System.out.println("\n Please Enter the Length of any Side: "); side = sc.nextDouble(); Area = (Math.sqrt(3)/4)*(side * side); Perimeter = 3 * side; Semi = Perimeter/2; Altitude = (Math.sqrt(3)/2) * side; System.out.format("\n The Area of a Equilateral Triangle = %.2f\n",Area); System.out.format("\n The Perimeter of a Equilateral Triangle = %.2f\n", Perimeter); System.out.format("\n The Semi Perimeter of a Equilateral Triangle = %.2f\n", Semi); System.out.format("\n The Altitude of a Equilateral Triangle = %.2f\n", Altitude); } }

**OUTPUT**

**ANALYSIS**

Following statements will allow the User to enter the length of any side in the Equilateral Triangle.

System.out.println("\n Please Enter the Length of any Side: "); side = sc.nextDouble();

Next line, we are using the Mathematical Formula to calculate the Area of an Equilateral Triangle. Here Math.sqrt() is the math function, which is used to calculate the square root

Area = (Math.sqrt(3)/4)*(side * side);

In the next line, We are calculating the Perimeter of an Equilateral Triangle using the formula

Perimeter = 3 * side;

Within the next line, We are calculating the semi perimeter of an Equilateral Triangle using the following formula. We can also find semi perimeter using the standard formula = (3* side) / 2.

Semi = Perimeter/2;

In the next line, We are calculating the Altitude of an Equilateral Triangle using the formula:

Altitude = (Math.sqrt(3)/2) * side;

Following System.out.format statements will help us to print the Perimeter, Semi Perimeter, Altitude and Area of an Equilateral Triangle

System.out.format("\n The Area of a Equilateral Triangle = %.2f\n",Area); System.out.format("\n The Perimeter of a Equilateral Triangle = %.2f\n", Perimeter); System.out.format("\n The Semi Perimeter of a Equilateral Triangle = %.2f\n", Semi); System.out.format("\n The Altitude of a Equilateral Triangle = %.2f\n", Altitude);

## Java Program to find Area of Equilateral Triangle using Functions

This Java program allows the user to enter length of any one side of an Equilateral Triangle. In this example, we are going to use the logic that we specified in first example but we will separated the logic and place it in a method.

**JAVA CODE**

// Java Program to find Area of Equilateral Triangle using Functions package Area; import java.util.Scanner; public class AreaOfEquilateralTriangleUsingMethods { private static Scanner sc; public static void main(String[] args) { double side; sc = new Scanner(System.in); System.out.println("\n Please Enter the Length of any Side: "); side = sc.nextDouble(); AreaofRightTriangle(side); } public static void AreaofRightTriangle( double side ) { double Area, Perimeter, Semi, Altitude; Area = (Math.sqrt(3)/4)*(side * side); Perimeter = 3 * side; Semi = Perimeter/2; Altitude = (Math.sqrt(3)/2) * side; System.out.format("\n The Area of a Equilateral Triangle = %.2f\n",Area); System.out.format("\n The Perimeter of a Equilateral Triangle = %.2f\n", Perimeter); System.out.format("\n The Semi Perimeter of a Equilateral Triangle = %.2f\n", Semi); System.out.format("\n The Altitude of a Equilateral Triangle = %.2f\n", Altitude); } }

**OUTPUT**

## Java Program to find Area of Equilateral Triangle using Oops

In this example, we are dividing the code using the Object Oriented Programming. To do this, First we will create a class which holds a methods.

**JAVA CODE**

package Area; public class AreaOfaEquilateralTriangle { public void AreaofEquilateralTriangle( double side ) { double Area, Perimeter, Semi, Altitude; Area = (Math.sqrt(3)/4)*(side * side); Perimeter = 3 * side; Semi = Perimeter/2; Altitude = (Math.sqrt(3)/2) * side; System.out.format("\n The Area of a Equilateral Triangle = %.2f\n",Area); System.out.format("\n The Perimeter of a Equilateral Triangle = %.2f\n", Perimeter); System.out.format("\n The Semi Perimeter of a Equilateral Triangle = %.2f\n", Semi); System.out.format("\n The Altitude of a Equilateral Triangle = %.2f\n", Altitude); } public double EquilateralTriangle( double side ) { double Area; Area = (Math.sqrt(3)/4)*(side * side); return Area; } }

Within the Main program, we will create an instance of the above specified class and call the methods.

**JAVA CODE**

package Area; import java.util.Scanner; public class AreaOfEquilateralTriangleUsingClass { private static Scanner sc; public static void main(String[] args) { double side, Area; sc = new Scanner(System.in); System.out.println("\n Please Enter the Length of any Side: "); side = sc.nextDouble(); AreaOfaEquilateralTriangle aet = new AreaOfaEquilateralTriangle(); aet.AreaofEquilateralTriangle(side); Area = aet.EquilateralTriangle(side); System.out.format("\n Second Method: The Area of a Equilateral Triangle = %.2f", Area); } }

**OUTPUT**

Thank You for Visiting Our Blog