Java Program to Calculate Area Of Triangle with 3 Sides Given


Calculate Area Of Triangle with 3 Sides Given program in Java

Formula to Calculate Area of Triangle with three sides given

Area of Triangle= s(s-a)(s-b)(s-c) where s= (a+b+c)/2

Calculate Area of triangle with 3 sides given using Java

import java.util.Scanner; class AreaOfTriangle { public static void main(String args[]) { Scanner sc= new Scanner(; System.out.println("Enter the 1st side of triangle:"); int a= sc.nextInt(); System.out.println("Enter the 2nd side of triangle:"); int b= sc.nextInt(); System.out.println("Enter the 3rd side of triangle:"); int c= sc.nextInt(); if((a+b)>c && (a+c)>b && (b+c)>a) { int s=(a+b+c)/2; double area=Math.sqrt(s*(s-a)*(s-b)*(s-c)); System.out.println("Area of Triangle is: " + area); } else System.out.println("Area of Triangle not exit"); } }


C:\Users\SK\Desktop\javaPrograms>java AreaOfTriangle Enter the 1st side of triangle: 20 Enter the 2nd side of triangle: 30 Enter the 3rd side of triangle: 40 Area of Triangle is: 290.4737509655563

Want to Clear Java Interview? Try our Java Interview Notes


Recommended Deals End in

Recommended Quiz
Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Search Tags