Westonci.ca is the best place to get answers to your questions, provided by a community of experienced and knowledgeable experts. Explore in-depth answers to your questions from a knowledgeable community of experts across different fields. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform.

Create a new project called 02.03 Math Class Methods. Create a class called PyTheorem in the newly-created folder. Use the appropriate Math class methods to calculate the hypotenuse of two right triangles. The value of each side (sides a and b) should be randomly generated using Math.random(). The range should from 5 (inclusive) to 23 (exclusive). Print the value of each side of both triangles as well as the value of the hypotenuse for both triangles.

Sagot :

Answer:

The program in Java is as follows:

import java.util.*;

public class PyTheorem{

   public static void main(String [] args){

       Random rNum = new Random();

       int a = rNum.nextInt(17) + 5;

       int b = rNum.nextInt(17) + 5;

       System.out.println("a: "+a);

       System.out.println("b: "+b);

       double hyp = Math.sqrt(Math.pow(a,2)+Math.pow(b,2));

       System.out.print("Hypotenuse: "+hyp);

   }}

Step-by-step explanation:

This generates random number for a

       int a = rNum.nextInt(17) + 5;

This generates random number for b

       int b = rNum.nextInt(17) + 5;

Print a

       System.out.println("a: "+a);

Print b

       System.out.println("b: "+b);

Calculate the hypotenuse

       double hyp = Math.sqrt(Math.pow(a,2)+Math.pow(b,2));

Print the calculated hypotenuse

       System.out.print("Hypotenuse: "+hyp);