# Java Program To Find Area Of Equilateral Triangle

Another exciting post, Java program to find the area of an equilateral triangle or to calculate the equilateral triangle in just two to three simple code lines. Most of the programs that you came across are good, but the length of the code was pretty annoying and confused too. So, we came up with the new code that works well, with a detailed explanation and online compile & execution too.

#Check out the online execution & Compiler tool below#

Before we entered into the analysis of how this java program works, let us give a brief explanation of what is an equilateral triangle and how to find the area of an equilateral triangle?

1) What is an equilateral triangle?

In geometry, an equilateral triangle is a triangle in which all three sides are equal. In the familiar Euclidean geometry, equilateral triangles are also equiangular; that is, all three internal angles are also congruent to each other and are each 60°.

2) Math formula for an Area of an equilateral triangle as follows :

√3/4 x S to the power of 2. Or Sˆ2, where S is the side of a triangle. Here is the java program to find/calculate the area of an equilateral triangle #Method-1 :

Output :

Very simple right! If you were new to java programming and get a little bit confused about how this program works :

Then there is the complete tutorial on how this java code will actually work to calculate the area of an equilateral triangle, we mostly covered each and every line of code here if you have any doubts related to this question then do comment here. We are glad to help you out.

1)

here in the above statement, we are importing features of scanner class.it is useful to take input from the user

2)

– here we created a class called AreaOfTriangle it consists of member functions (main function) and data member(variables like s,a,area…) we can create an object for this class but for this program no need of an object.

3)

: This is the main function and it is the indication for the processor to start the execution. here one important thing is it consists of a  formal argument of string args[]. it is useful to give input through command line at before running the program. (after compilation)

4)

: Scanner – it is a class which is stored in a java.util package which is inbuilt with the JDK uses to read the inputs from the various devices, whereas System.in – represents you were forcing the system to read the inputs from the input devices like keyboard etc.scanner  will give access on a console using some inbuilt method

5)

This method is used to print the given data on console.it is useful to give instructions to user.and display result of the program.

6)

: Once you were entered the side of the triangle, the system needs to allocate some space in order to execute the program and continues to last step.

The purpose of using the “Double ” here, the answer may be in decimal points to sometimes. Or considers as 158.26 or 552.223. Whereas ” Int ” can only read I/O before the decimal points.

7)

: The answer can be stored in the area, and formula to represent the area of the equilateral triangle.

note: we use a method called sqrt(){finds the square-root of value } it is in a class called  Math it is consists of many methods for a complex calculation like square root etc.

8)

: Now the area of the triangle will be displayed on the screen.

That’s the complete step by step process. About how this java code works. You can also represent the code in different ways. But, smaller is better right :P. Moreover, below is the execution file, you can give any standard arguments, and note down the outputs.

# Sample Method – 2 ( online compiler and execution tool )

Here, the code is slightly modified, just taking input in other form using command line arguments. input will send to the main function to store that values we created a string array in the main function(String args[]).

ex:  step for execution on cmd:

javac MyClass.java     —————-> compiling

java MyClass  10 20 30 ————–> executing and sending arguments to the main function.

args={“10″,”20″,”30”}:

arg=>”10″

arg=>”20″

arg=>”30″

all values are in string form we want in number form to get that we have a method called parseXXX(); it takes input as string convert into a number.

this concept was used in below program look at once analyse it.

Enter your own values, to know the area of an equilateral triangle. You can also use the int.

That’s the method to know the area of an equilateral triangle, how simple it was right :).

If you need to know any more information about the above program and how does it work, do contact us. We are glad to help you out.

If you find any bug in the program do let us know by contacting us or comment here.

#java program to find the area of an equilateral  triangle end #