Question

Problem a (PA4a.java) Write a program to evaluate the area of a triangle given the lengths of its sides using Herons Formula. Here is an outline: Get the three side lengths from the user (which might have decimal values): a, b, c. Check to ensure that the sides are valid for a triangle. Importantly, the sum of the lengths of any two sides must be larger than the length of the third side (you must check all three sides this way). Calculate the semiperimeter (s): 1. 2. 3. a+b+c 2 4. Calculate the area: area = V s(s-a) (s-b)(s-c) You must format the output to have two decimal places (even if they are both o), and round if necessary. For example: Enter the length of side a: 3 Enter the length of side b: 4 Enter the length of side c: 5 The area is 6.00 http://en.wikipedia org/wiki/Heron%27.formula
media%2F877%2F87733a0c-6d11-4bdc-ad38-3d
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student,

here is the complete Java code which perform the required task.

Please note that the below code has been compiled using javac compiler in ubuntu 16.04 system.

-------------------------------------------------------------------------------------------------------------------------------------

Program:

-------------------------------------------------------------------------------------------------------------------------------------

//import the required packages

import java.util.Scanner;

import java.lang.*;

//public class

public class Area
{

    //main class

    public static void main(String[] args)
    {

        //scanning input

        Scanner input = new Scanner(System.in);

        System.out.printf("Enter the length of side a: ");

        int a = input.nextInt();

        System.out.printf("Enter the length of side b: ");

        int b = input.nextInt();

        System.out.printf("Enter the length of side c: ");

        int c = input.nextInt();

        //calculating the seme-perimeter

        double s = (a + b + c) /2;

        //calculating the area

        double A = Math.sqrt(s * (s - a) * (s - b) * (s - c));

        //display the area

System.out.println("The area is: "+A);

    }

}//end of the program


------------------------------------------------------------------------------------------------------------------------------------------

here i have attached the output of the program as a screen shot..

Output:

-----------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------------------

Kindly Check and Verify Thanks...!!!

Add a comment
Know the answer?
Add Answer to:
Problem a (PA4a.java) Write a program to evaluate the area of a triangle given the lengths...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT