Java program to find the area of a triangle


Area of a triangle is half the product of its base and height. Therefore, to calculate the area of a triangle.

  • Get the height of the triangle form the user.
  • Get the base of the triangle form the user.
  •  Calculate their product and divide the result with 2.
  • Print the final result.

Example

import java.util.Scanner;
public class AreaOfTriangle {
   public static void main(String args[]){
      int height, base, area;
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the height of the triangle ::");
      height = sc.nextInt();
      System.out.println("Enter the base of the triangle ::");
      base = sc.nextInt();
      area = (height* base);
      System.out.println("Area of the triangle is ::"+area);
   }
}

Output

Enter the height of the triangle ::
14
Enter the base of the triangle ::
5
Area of the triangle is ::70

Updated on: 13-Mar-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements