Java Chapters

Java Program to Calculate the Area of a Triangle

Structure of JAVA Programs - Overview
import java.util.Scanner;
import java.lang.*;

public class Program 
{
    public static void main( String[] args ) 
    {
        int A, B, C, S, Area;
        Scanner reader = new Scanner(System.in);
        
        System.out.println("Enter Length of Rectangle : ");
        A = reader.nextInt();
        B = reader.nextInt();
        C = reader.nextInt();
       
        S = (A + B + C) / 2;
        Area = (int) Math.sqrt(S * (S - A) * (S - B) * (S - C));
        
        System.out.println("\nArea of Rectangle is : " + Area);
    }
}

Output :
Enter Length of Triangle's three sides : 10
20
20

Area of Triangle is : 96

Description :

Area of Trangle can be calculated as
s x (s-a) x (s-b) x (s-c)

Where s = half the perimeter (a+b+c)/2


Leave a comment
Recent Comments
No Comments