Java program to calculate triangle area

Views: 163   

Following program shows you how to calculate triangle area.
This program gets triangle base and height from user and calculates area and prints it using following formula
Area = base X height / 2

import java.util.Scanner;

public class MathGeometry1 {

    public static void main(String[] args) {

        double triangleBase;
        double triangleHeight;

        Scanner in = new Scanner(;

        System.out.println("Enter the base of triangle:");
        triangleBase = in.nextDouble();

        System.out.println("Enter the height of triangle:");
        triangleHeight = in.nextDouble();

        double areaOfTriangle = (triangleBase * triangleHeight) / 2;
        System.out.println("Area of triangle is: " + areaOfTriangle);



Enter the base of triangle:
Enter the height of triangle:
Area of triangle is: 3.0
On By