Java Program to Find Area of Right Angled Triangle

  • Write a Java program to find the area of a Right Angled Triangle.
  • What is the formulae to calculate area of triangle.

To calculate the area of a Right-angled triangle, first we need to understand some fundamental properties of a right angled triangle. Right triangle is a triangle in which one angle is a right angle (90 degree). The sum of the other two angles of right-angled triangle is 90 degree.

Sides of Right Triangle

  • Base and Perpendicular : The two adjacent sides of the right angle. These are the two sides of a triangle which are not hypotenuse.
  • Hypotenuse : Hypotenuse is the longest side of a right angled triangle which is opposite the right angle.

Area of Right angled Triangle
Area of Right triangle, if we know the length of base and perpendicular.
  • Area of Right Triangle = (1/2)* Base * Perpendicular

If we know the length of hypotenuse and altitude of a right triangle, then we can use below mentioned formula to find area of a right triangle.
  • Area of Right Triangle = (1/2)* Hypotenuse * Altitude
Where, Altitude is the perpendicular distance between hypotenuse and vertex containing right angle(vertex opposite of hypotenuse).

Java program to calculate area of right triangle

package com.tcc.java.programs;

import java.util.*;

class TriangleArea {
    public static void main(String args[]) {
    double base, height, area;
 
    Scanner in = new Scanner(System.in);
    System.out.println("Enter length of base of Triangle");
    base = in.nextDouble();

    System.out.println("Enter length if height of Triangle");
    height = in.nextDouble();

    // Area if Triangle = (Base X Height)/2;
    area = (base * height)/2;
    System.out.println("Area of Triangle = " + area);      
   }
}
Output
Enter length of base of Triangle
3.0
Enter length if height of Triangle
4.0
Area of Triangle = 6.0

Recommended Posts
Java Program to find Area Of Equilateral Triangle
Java Program to Find Area Of Triangle
Java Program to calculate area and circumference of circle
Java Program to Find Area of Right Angled Triangle
Java Program to Calculate Volume of Sphere
Java Program to Find Volume and Surface Area of Cuboid
Java Program to Calculate Volume and Surface Area of Cone
Java Program to Find Surface Area and Volume of Cylinder
Java Program to Calculate Surface Area and Volume of Cube
Java Program to Print Pascal Triangle
Java Program to Print Right Triangle Star Pattern
All Java Programs