How to calculate the area and the heights of the triangle in Java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to calculate the area and the heights of the triangle in Java?

Input 3 numbers a, b, c Output area and heights

6th Nov 2022, 7:33 AM
Lily
Lily - avatar
3 Answers
+ 4
Kind of an unclear question. What are the numbers a,b and c? Are they the length of the sides? If they are the length of the sides, then you can use the formula to get the area: A=√(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2 but there will be three heights for triangles which depends on the sides : so you can get the heights : h=A*2/(a or b or c) Also show your attempt so that we can help you in your code.
6th Nov 2022, 7:48 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
https://code.sololearn.com/co2J4Rj1u6M3/?ref=app Thank you so much! This is my code.
6th Nov 2022, 9:45 AM
Lily
Lily - avatar
+ 2
The only problem I can see in your code is, it takes input as int variable.So when the output is decimal it shows error.So just declare double of every variable so that it can take a decimal value: https://code.sololearn.com/c51I7U8Z3JF/?ref=app
6th Nov 2022, 12:28 PM
The future is now thanks to science
The future is now thanks to science - avatar