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
These things are commonly found on the front of desktop computer cases:
jok3333 [9.3K]

USB ports, headphone jack/microphone port, and of course, a power button.

3 0
3 years ago
What can we do to positive interaction online?
Julli [10]

Answer:

We can help eachother out with things.

Explanation:

Eg. Schoolwork and homework because our stress level will decrease.

8 0
2 years ago
Read 2 more answers
Name three output devices
san4es73 [151]

Monitor

Printers

Plotters.

8 0
2 years ago
Apart from the challenges of heterogeneity, business and social change and trust and security, identify other problems and chall
Klio2033 [76]

Answer:

The challenge of cost control

The challenge of competence

The challenge of reduced system delivery times.

Explanation:The Challenge of Cost control is a major challenge affecting the software engineering in the 21st century,the cost of Microchips and other hardware are constantly rising.

The challenge of competence is another major challenge affecting software engineering in the 21st century,as most software engineers lack the required competence to handle some of the issues facing softwares.

The challenge of reduced system delivery times is a major challenge likely to affect software engineering in the 21st century,as people required the software to be available in the shortest possible time.

7 0
3 years ago
Copyright Laws provide_______ for the owners of creative works.
viktelen [127]
They provide protection
7 0
3 years ago
Other questions:
  • What is the Multiplier if the change in RGDP is $525,000,000 and initial spending is $100,000?
    12·1 answer
  • Name the component used in first generation of computer​
    10·1 answer
  • 1. Write an expression whose value is the result of converting the str value associated with s to an int value. So if s were ass
    12·1 answer
  • Write a program that reads students’ names followed by their test scores. The program should output each student’s name followed
    13·1 answer
  • What type of game is LEAST LIKELY to need a structured narrative?
    6·1 answer
  • Jane receives an email claiming that her bank account information has been lost and that she needs to click a link to update the
    13·1 answer
  • Practicing touch typing allows you to create documents efficiently and accurately.
    13·1 answer
  • What is Roko's Basilisk?
    7·1 answer
  • ¿Qué son las tecnologías modernas?
    6·1 answer
  • In what ways are super computer different from mainframe computers.​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!