Area of Triangle in Java
Here you will know and get the program code to calculate the Area of Triangle in Java programming.
Formula
Area of Triangle = (width * height) / 2
Find Area of Triangle in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import java.util.Scanner; public class TriangleArea{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the width of triangle : "); double width = scanner.nextDouble(); System.out.print("Enter the height of triangle : "); double height = scanner.nextDouble(); scanner.close(); //calculate area of triangle double area = (width * height) / 2; System.out.println("The area of the triangle is: " + area); } } |
Output
C:\CodeRevise\java>javac TriangleArea.java
C:\CodeRevise\java>java TriangleArea
Enter the width of triangle : 12
Enter the height of triangle : 15
The area of the triangle is: 90.0
Check out our other Java Programming Examples