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
Type the correct answer in the box. Use numerals instead of words. If necessary, use / for the fraction bar. What will be the ou
lord [1]

Answer:

2

Explanation:

The output of the Java program is 2. The public Vehicle class is defined with the class variable 'counter'. When a Vehicle class object is instantiated, the counter variable increments by one.

In the program, the two instances of the class are created, incrementing the counter variable to two, the print statement outputs 2 as the result of the program.

8 0
3 years ago
Select the correct answer.
Andrei [34K]

Answer: The answer is C

Explanation: When it comes to research papers your topic shouldnt be too broad. Your topic should be broad enough you can find a good amount of information but not too focused that you can't find any information.

7 0
2 years ago
What are 3 possible causes of getting a "network cable unplugged" message on a pc, assuming that the cable is not actually unplu
Nat2105 [25]
I've had that problem before. The cause of my problem was 2 things and that was the age of the cable, and build up of dust on each of the cable.
7 0
3 years ago
To set up or modify a saved object in Access use the
vovangra [49]
A primary view saved object in
4 0
3 years ago
The benefits associated with software reuse are lower cost, better quality,
Sholpan [36]

Answer:

Software reuse is the technique through which updating the software system through the already defined components or assets of the software.This helps in increasing the productivity ,cost decrement , quality improvement etc.

But in actual case, the software reuse still persist high cost due to modification of inflexible designing of software .It also costs more than expected for the maintenance and training of software.

The security of the software is always at risk because of the usual and advanced hacking and attacking by the hackers even when the protect of software is high.Thus, these statements verify that the benefits of cost and security of software is not actually realized.

6 0
3 years ago
Other questions:
  • How to write a program converting RGB to CMYK in python
    6·1 answer
  • ___________is a security strategy that applies multiple layers of defense because there is an assumption that any single protect
    12·1 answer
  • Write a java program which uses methods for calculating the sum of any 5 non-zero integer digits that are input. The program mus
    8·1 answer
  • When a partition is formatted with a file system and assigned a drive letter it is called a volume?
    10·1 answer
  • Review universal data models and discuss how these are being used more widely today. Does a data modeling project using a packag
    9·2 answers
  • Which is the highest level of the hierarchy of needs model?
    14·1 answer
  • Select the best answer from the drop-down menu. ________ networks use cables connected directly to the computer. Signals sent in
    11·1 answer
  • This function chooses the screen to display based on the score.What is the correct way to call this function?
    13·2 answers
  • What type of task can be defined to allow you fine-grained control over the management tasks a user can perform in an OU
    14·1 answer
  • quizlet ann is a security professional for a midsize business and typically handles log analysis and security monitoring tasks f
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!