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 foundational domain for business
mr Goodwill [35]

a fundamental domain or fundamental region is a subset of the space which contains exactly one point from each of these orbits . It serves as a geometric realisation for the abstract set of representatives of the orbits . There are many ways to choose a fundamental domain .

hope this help

7 0
3 years ago
Explain the principles of computer applications ​
9966 [12]

Answer:

The nature of computers and code, what they can and cannot do.

How computer hardware works: chips, cpu, memory, disk.

Necessary jargon: bits, bytes, megabytes, gigabytes.

How software works: what is a program, what is "running"

How digital images work.

Computer code: loops and logic.

Big ideas: abstraction, logic, bugs.

3 0
2 years ago
_____ allow you to logically separate ports in switches to create subdomains without wiring your network as physical subdomains.
AlladinOne [14]

Answer:

The correct answer for the following question is VLAN.

Explanation:

It stands for Virtue Logical Area Network which allows you to group port on a switch logically. VLANs can be extend across (a period of time) multiple switches means you used to express on port that you're in that VLAN by changing the VLAN number.

We have the ability to improve our security with VLANs by controlling what VLAN is accessing with the other network of VLANs. So that this network is particularly helpful in office situation to create subdomain without wiring physical domain as your network.

6 0
2 years ago
What can Strings store
horsena [70]
A string is generally considered as a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding. String may also denote more general arrays or other sequence (or list) data types and structures.
5 0
3 years ago
Read 2 more answers
Where do you place the title tag in HTML​
makkiz [27]

Answer:

The title tag is basically your saved document

Save as and poof

High Hopes^^

Barry-

5 0
2 years ago
Other questions:
  • This type of server spools documents and puts them in a queue.
    12·1 answer
  • To select a number format, you can choose a category in the Number tab in the Format Cells dialog box and then select the number
    5·1 answer
  • An object reference provides a(an)______for an object and is used to gain access to the object (Points : 2) entry
    11·1 answer
  • What is the protocol in the web search at the bottom?
    13·1 answer
  • Rank these three account types in order of decreasing liquidity. Start by picking the most liquid account type first
    13·2 answers
  • Which data type or collection of data types can SOQL statements populate or evaluate to?
    9·1 answer
  • There are ___ Federal Reserve Banks. Each bank is also in charge of its assigned District Banks.
    10·1 answer
  • Microsoft Excel is an example of a(n) application.
    11·2 answers
  • Pls help. will give brainliest to FIRST and CORRECT answer!
    14·1 answer
  • 5. Give one word answers:
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!