Java Program to Calculate Area Of Triangle with 3 Sides Given

[3460 views]




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.in); 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"); } }

Output

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
                 



Clear Any Java Interview by Reading our Ebook Once.


Can you clear Java Interview?




Comments










Search Anything:

Sponsored Deals ends in



Interesting Technical Quizzes:

Search Tags