Java program to find the area of a triangle

Java Programming Java8Object Oriented Programming

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
raja
Published on 26-Apr-2018 06:23:03
Advertisements