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
Write an expression that will cause the following code to print "Equal" if the value of sensorReading is "close enough" to targe
natali 33 [55]

Answer:

The C++ code is given below with appropriate comments

Explanation:

//Remove this header file if not using visual studio.

#include "stdafx.h"

//Include the required header files.

#include <iostream>

//Use for maths function.

#include <cmath>

using namespace std;

//Define main function

int main()

{

      // Define the variables

      double targetValue = 0.3333;

      double sensorReading = 0.0;

      //Perform the opeartion.

      sensorReading = 1.0 / 3.0;

      // Get the absolute floating point value and

      // Check up to 4 digits.

      if (fabs(sensorReading - targetValue) < 1E-4)

      {

             //Print equal if the values are close enough.

             cout << "Equal" << endl;

      }

      else

      {

             //Print not equal if the values are not                  

             //close enough.

             cout << "Not equal" << endl;

      }

      system("pause");

      //Return the value 0.

      return 0;

}

5 0
3 years ago
If you create a column break, what happens to the text after the insertion point?
Ugo [173]

Answer:

It moves to the top of the next column.

5 0
3 years ago
Cultural differences may make it difficult for team members to _____. Select 4 options.
ludmilkaskok [199]

Answer:

A) collaborate with each other

C) achieve business objectives

D) understand each other

E) resolve conflict and problems

Explanation:

Well lets use the process of elimination. If there are cultural differences then there are different cultures involved. So B doesn't work because it's multicultural when there is different cultures. And you need 4 answers out of 5, so all you need to do is eliminate one answer.

Good Luck! You got this!

6 0
3 years ago
The Class of computers used in <br>scientific applications are called​
sashaice [31]

Answer:

sala de informática

Explanation:

salas de informática são utilizadas cada vez mais no mundo pelo aumento excedente de uso da tecnologia os estudantes precisam aprender conceitos básicos de informática e eletrônica

5 0
3 years ago
A variable like userNum can store a value like an integer. Extend the given program to print userNum values as indicated. (1) Ou
Olin [163]

Answer:

Write the following lines of code just before the return statement

//1

       System.out.println("You entered "+userNum);        

       // 2

       System.out.println(userNum+" squared is "+(Math.pow(userNum, 2))+" and "+userNum+" cubed is "+(Math.pow(userNum, 3)));

       //3

       int userNum2 = 0;

       System.out.print("Enter another integer: ");

       userNum2 = scnr.nextInt();

int sum = userNum + userNum2;

       System.out.println(userNum+" + "+userNum2+" is "+sum);

int product = userNum * userNum2;

       System.out.println(userNum+" * "+userNum2+" is "+product);

Explanation:

I continued the program from where you stopped in the question

The explanation has been added as an attachment

Download docx
4 0
4 years ago
Other questions:
  • Is the internet useful and why
    7·2 answers
  • A ____ port is a connection in which eight data lines transmit an entire byte of data at one moment in time.​
    10·1 answer
  • How can you create balance to your drawing using only grayscale values?
    12·1 answer
  • Java languageThe cost to ship a package is a flat fee of 75 cents plus 25 cents per pound.1. Declare a constant named CENTS_PER_
    5·2 answers
  • What term is given to pieces of computer software that allow you to manage your e-mail from your computer?
    12·1 answer
  • Organizations should communicate with system users throughout the development of the security program, letting them know that ch
    12·1 answer
  • Suppose that L is a sorted list of 1,000,000 elements. To determine whether the x item is in L, the average number of comparison
    14·1 answer
  • An anagram of a string is another string with the same characters in the same frequency, in any order. For example 'ab', 'bca, a
    5·1 answer
  • Anyone here codes? <br> C++, C#, Lua? Anything?
    15·2 answers
  • A company wants to transmit data over the telephone, but they are concerned that their phones may be tapped. All of their data i
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!