Java Program Area of Triangle by Three Sides

By | July 7, 2019

Task: Write a Java Program Area of Triangle by Three Sides.

The Source Code of Java Program Area of Triangle by Three Sides

/*
 * Write a Java program to find the
area of a triangle when lengths of 
three sides are given.
*/
package trianglearea;
import java.util.Scanner;
/**
 * @author www.EasyCodebook.com
 */
public class TriangleArea {

    public static void main(String[] args) {
        double a,b,c, s, area;
        Scanner input=new Scanner(System.in);
        System.out.print("Enter length of side1:");
        a=input.nextDouble();
        System.out.print("Enter length of side2:");
        b=input.nextDouble();
        System.out.print("Enter length of side3:");
        c=input.nextDouble();
        s = (a+b+c)/2.0;
        area= Math.sqrt(s*(s-a)*(s-b)*(s-c));
        System.out.println("Area of Triangle with Heron Formula:"+area);

    }
}

Output of Java Program Area of Triangle by Three Sides:

Enter length of side1:5
Enter length of side2:5
Enter length of side3:5
Area of Triangle with Heron Formula:10.825317547305483

One thought on “Java Program Area of Triangle by Three Sides

  1. Pingback: Design and Use Triangle Class - C++ Program | EasyCodeBook.com

Leave a Reply

Your email address will not be published. Required fields are marked *