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
velikii [3]
3 years ago
9

Write a program consisting of: a. A function named right Triangle() that accepts the lengths of two sides of a right triangle as

arguments. The function should determine and return the hypotenuse of the triangle. b. A main() function that should call right Triangle() correctly and display the value the function returns.
Computers and Technology
1 answer:
Lunna [17]3 years ago
4 0

Answer:

The java program is as follows.

import java.lang.*;

public class Triangle

{

   //variables to hold sides of a triangle

   static double height;

   static double base;

   static double hypo;

   //method to compute hypotenuse

   static double rightTriangle(double h, double b)

   {

       return Math.sqrt(h*h + b*b);

   }

public static void main(String[] args) {

    height = 4;

    base = 3;

    hypo = rightTriangle(height, base);

 System.out.printf("The hypotenuse of the right-angled triangle is %.4f", hypo);

}

}

OUTPUT

The hypotenuse of the right-angled triangle is 5.0000

Explanation:

1. The variables to hold all the three sides of a triangle are declared as double. The variables are declared at class level and hence, declared with keyword static.

2. The method, rightTriangle() takes the height and base of a triangle and computes and returns the value of the hypotenuse. The square root of the sum of both the sides is obtained using Math.sqrt() method.

3. The method, rightTriangle(), is also declared static since it is called inside the main() method which is a static method.

4. Inside main(), the method, rightTriangle() is called and takes the height and base variables are parameters. These variables are initialized inside main().

5. The value returned by the method, rightTriangle(), is assigned to the variable, hypo.

6. The value of the hypotenuse of the triangle which is stored in the variable, hypo, is displayed to the user.

7. The value of the hypotenuse is displayed with 4 decimal places which is done using printf() method and %.4f format specifier. The number 4 can be changed to any number, depending upon the decimal places required.

8. In java, all the code is written inside a class.

9. The name of the program is same as the name of the class having the main() method.

10. The class having the main() method is declared public.

11. All the variables declared outside main() and inside another method, are local to that particular method. While the variables declared outside main() and inside class are always declared static in java.

You might be interested in
What is the first step a user should take toward generating an index?
Ad libitum [116K]

Answer:

I think that it's A

Explanation:

5 0
3 years ago
If you wanted to make certain numbers in a spreadsheet stand out, you should _____.
almond37 [142]
Make the numbers in bold and/or underlined
3 0
3 years ago
Read 2 more answers
What benefit does internet have​
Licemer1 [7]
Information can be transferred and passed way easier.
5 0
3 years ago
Http://moomoo.io/?server=8:16:0
love history [14]

Explanation:

noooooooooooooooooooooooooooooooooo

5 0
3 years ago
Read 2 more answers
Inc AX,2 is valid in assembly language ?
masya89 [10]

Answer:

in most so yes

Explanation:

4 0
3 years ago
Other questions:
  • The following is true about SPAM ________.
    9·1 answer
  • Write a Python function merge_dict that takes two dictionaries(d1, d2) as parameters, and returns a modified dictionary(d1) cons
    5·1 answer
  • Which loan type requires you to make loan payments while you’re attending school?
    9·1 answer
  • In an airline reservation system, on entering the flight number, the flight schedule and the flight status are displayed. In thi
    13·2 answers
  • If you delete a sent message on gmail does the person still get it
    14·1 answer
  • Assume that a picture is represented on a monitor screen by a rectangular array containing 2048 columns and 1536 rows of pixels.
    12·1 answer
  • Which of the following controls will provide an area in the form for the user to enter a name? a. button b. label c. text box d.
    8·1 answer
  • When a guest is wearing the medallion, they can order a drink with their smartphone or open their cabin door automatically by st
    13·1 answer
  • Tina reported a safety hazard at her workplace to OSHA. Representatives from OSHA came to her work and inspected the issue, then
    14·1 answer
  • EDI, ________, smart cards, and digital certificates are designed to support safe and secure online transactions.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!