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
You have been asked to create a query that will join the Production.Products table with the Production.Categories table. From th
Flauer [41]

Answer:

The Fastest car in the world would be between 1,184 Horse Power-1,106 Torque

Explanation:

6 0
3 years ago
5. Why are female fans particularly valuable to the sports industry? Cite two<br> specific reasons.
shusha [124]

Answer:Females make up a large part of the market. The female fans often times spend more on things and have a greater amount of it, so if they are able to target them, they have a gained a large amount of the market

Explanation:

hope it helps

7 0
3 years ago
The ____ method returns an integer that represents the location of the substring within the string.
enot [183]

Insert Method

it is used to returns an integer that speaks to the area of the substring inside the string.

5 0
3 years ago
When we focus on stereotypes we may ___________________. a. experience culture shock b. develop ethnocentrism c. unconciously lo
alisha [4.7K]
When we focus on stereotypes we may <span>unconsciously look for information to support our generalizations .</span>
3 0
2 years ago
Read 2 more answers
is skill in using productivity software, such as word processors, spreadsheets, database management systems, and presentation so
Digiron [165]

Answer:

It is general knowledge

Explanation:

What you covered is general knowledge and the entrance to computer science.

4 0
3 years ago
Other questions:
  • What is the last step in planning your budget
    11·1 answer
  • Write code that inserts userItem into the output string stream itemsOSS until the user enters "Exit". Each item should be follow
    5·1 answer
  • _____ is the widely used transport layer protocol that most Internet applications use with Internet Protocol (IP).
    9·1 answer
  • you are the manager of a virtual team that is working on a project. You uploaded a Word document to an OneDrive account that you
    9·1 answer
  • When using a function to preform a calculation how would you select the range of numbers to use
    13·1 answer
  • Andy, a developer, is designing a new program. Which tool should Andy use to help him complete his task?
    13·1 answer
  • Buenas , ayudenme con esta tarea de excel 2016
    6·1 answer
  • In a swap you need a variable so that one of the values is not lost ? Need help
    7·2 answers
  • Edhesive 3.4 practice 1
    9·1 answer
  • How do you change your name on your brainly profile
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!