Java Program To Find Area Of Equilateral Triangle | Programs
Beginners Programs :

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 & Complier 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 ? ( Oops * I knew it , you know the answer but just a couple of lines 😛

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.

equilateral traingle area in java

Here is the java program to find/calculate 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 here is the complete tutorial on how this java code will actually work to calculate 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 above statement we are importing features of scanner class.it is  usefull to take input from the user

2)

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

3)

 : This is the main function and it is the indication for the processer to start the execution.here one important thing is it consist 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 console using some inbuilt method

5)

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

6)

: Once you were entered the side of the triangle , the system need 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 using a method  called sqrt(){finds the squareroot of value } it is in a class called  Math it is consists  of many methods for  complex calculation like squareroot 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 main function  to store that values we created a string array  in main function(String args[]).

ex:  step for excution on cmd:

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

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

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

arg[0]=>”10″

arg[1]=>”20″

arg[2]=>”30″

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

this concept was use 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 #