1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
icang [17]
3 years ago
8

Write a program that reads the lengths of the sides of a triangle from the user. Compute the area of the triangle using Heron's

formula (below), in which s represents half of the perimeter of the triangle and a, b, and c represent the lengths of the three sides. Print rhe area to three decimal places.
Area= √ s(s-a)(s-b)(s-c)
Computers and Technology
1 answer:
slamgirl [31]3 years ago
3 0

Answer:

The java program is as follows.

import java.util.Scanner;

import java.lang.*;

public class Area

{

   //variables to hold the values

   static double a, b, c;

   static double s;

   static double area;

public static void main(String[] args) {

    //scanner class object created

    Scanner sc = new Scanner(System.in);

 System.out.print("Enter the first side: ");

 a=sc.nextInt();

 System.out.print("Enter the second side: ");

 b=sc.nextInt();

 System.out.print("Enter the third side: ");

 c=sc.nextInt();

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

 //function of Math class used

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

 //result displayed with 3 decimal places

 System.out.printf("The area of the triangle is %.3f", area);  

}

}

OUTPUT

Enter the first side: 1

Enter the second side: 1

Enter the third side: 1

The area of the triangle is 0.433

Explanation:

1. The variables to declare the three sides of the triangle, the semi-perimeter and the area of the triangle are declared with double datatype. All the variables are declared at class level and hence, declared with keyword, static.  

2. Inside main(), an object of the Scanner class is created.

Scanner sc = new Scanner(System.in);

3. Using the Scanner class object, user input is taken for all the three sides of the triangle.

4. Following this, the semi-perimeter is computed as shown.

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

5. The area of the triangle is computed using the given formula which is implemented as shown.

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

6. The sqrt() method of the Math class is used while computing the area of the triangle.

7. The area is displayed with three decimals. This is done using the printf() method as shown.

System.out.printf("The area of the triangle is %.3f", area);

8. The program is saved with the same name as the name of the class having the main() method.

9. The class having the main() method is always public.

You might be interested in
Nila has created a report, and now she would like to a create table of contents. Nila has reviewed her report and decides to add
Alenkinab [10]

Answer:

The answer is "heading"

Explanation:

Headings, which appear into your document must be marked simply, objectively and correctly because it shows the final report structure and enable to easy access with specific information.  

  • It also promotes to read the document. So, its consistency is ensured in the headings.
  • In sort documents, it can't require any heading, but it Nila created a report, in which she requires  heading and then she update the content of the tables, and other choices can't be described in the given scenario, that's why it is correct
5 0
3 years ago
Does any body know how to bypass easy anti cheat on crossout
dolphi86 [110]

Answer:

It is very hard as easy anticheat is the leading anticheat right now, you can do some web surfing and maybe find out.

6 0
2 years ago
Technician A says that wheel speed sensors are a highly probable cause of illuminated EBC warning lamps. Technician B says that
Blababa [14]

Technician A because

3 0
2 years ago
___ is an example of a calling statement.
Naddika [18.5K]

Answer:

printf("%f", roi(3, amt));

Explanation:

To call the function, we have to put the function name without return type and if the function have parameter then we have to pass the parameter without data type as well.

Let discuss the options:

Option A: float roi(int, double);

it is not a calling, it is used to declare the function. In calling, return type of the function like float and data type of the parameter does not pass like int, double.

Option B: printf("%f", roi(3, amt));

print is used to display the result, inside the print it call the function. It is correct way to call the function.

Option C: float roi( int yrs, double rate);

it is not a calling, it is used to declare the function. In calling, return type of the function like float and data type of the parameter does not pass like int, double.

Option D: float roi( int yrs, double rate)

Same reason as option C.

Therefore, the option B is correct option.

4 0
2 years ago
Read 2 more answers
The best time to visit a college is: A. during spring break. B. on a weekend. C. when the college is in session. D. during winte
GaryK [48]
When the college is in session
5 0
3 years ago
Read 2 more answers
Other questions:
  • What is the next series of dragon ball super
    6·2 answers
  • Mr. Olgesandravich is proctoring students working at their own pace in an online class. He is generating a spreadsheet that show
    15·1 answer
  • Which of the given original work is protected by the copyright law
    9·1 answer
  • Which are valid double statements for java? double a = 0; double b = -1.0; double c = -425; double d = 6340; double e = -1.0; do
    12·2 answers
  • What is the function of the capsid? it allows a virus to live independently. it is composed of genetic material. it destroys the
    12·2 answers
  • You coded the following class: public class N extends String, Integer { }When you compile, you get the following message:N.java:
    9·1 answer
  • The degree to which a firewall can impose user access restrictions is known as which of the following?Security assurancePrivileg
    8·1 answer
  • How to unsubscribe from Brainly
    6·2 answers
  • In what document does the program manager (pm) address the demilitarization and disposal requirements?
    7·1 answer
  • Assume that an int variable age has been declared and already given a value. Assume further that the user has just been presente
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!