Java program to find area of triangle

Let’s learn java program to find area of triangle.

Java program to find area of triangle

In the below area of triangle java program first user enters base-width and height of triangle using nextDouble() method of Scanner class. To calculate area of triangle java formula is:

Area = (width * height) / 2

Here’s the java program to find area of triangle.

import java.util.Scanner;
public class FindAreaOfTriangle
{
   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter width of triangle: ");
      double base = sc.nextDouble();
      System.out.println("Please enter height of triangle: ");
      double height = sc.nextDouble();
      // formula area of triangle = (base * height) / 2
      double area = (base * height) / 2;
      System.out.println("Area of triangle is: " + area);
      sc.close();
   }
}

Output:

Please enter width of triangle: 5
Please enter height of triangle: 5
Area of triangle is: 12.5


Also read – major features of java