# Java program for area of triangle

Contents

### Program Description

Write a java program to calculate the area of triangle. The area of triangle of base b , and height h is calculated using the mathematical formula:

$Area&space;of&space;Triangle&space;=&space;\frac{&space;base&space;*&space;height}{&space;2}$

### Java Program

The Java program prompts the user to enter base and the height of the triangle.

It computes the area of the triangle using the formula.

import java.util.Scanner;
/***************************************************************** * AreaOfTriangle.java * @program : Java program to calculate the area * @web : www.testingdocs.com * @version : 1.0 ******************************************************************/
public class AreaOfTriangle
{ public static void main(String args[]) { Scanner s= new Scanner(System.in); System.out.println("Enter the width of the Triangle:"); double b= s.nextDouble(); System.out.println("Enter the height of the Triangle:"); double h= s.nextDouble(); //Area = (width*height)/2 double area=(b*h)/2; System.out.println("Area of Triangle is: " + area); }
}

### Program Output

Enter the width of the Triangle:
45
Enter the height of the Triangle:
65
Area of Triangle is: 1462.5