Ask Question

Write a Java application that uses the Math class to determine the answers for each of the following: a. The square root of 37 b. The sine and cosine of 300c. The value of the floor, ceiling, and round of 22.8 d. The larger and the smaller of the character 'D' and the integer 71 e. A random number between 0 and 20 (Hint: The random () method returns a value between 0 and 1; you want a number that is 20 times larger.) Save the application as MathTest. java.'

+2
Answers (1)
  1. 15 July, 17:27
    0
    import java. util. Random;

    public class MathTest {

    public static void main (String[] args) {

    int a = 37, b = 300;

    double c = 22.8;

    int max;

    System. out. println ("The Square root of 37 is " + Math. sqrt (a));

    System. out. println ("The Sine of 300 is " + Math. sin (b) + " and the cosine is " + Math. cos (b));

    System. out. println ("The Floor, Ceiling and Round Value of 22.8 respectively are "+Math. floor (c) + ", "+Math. ceil (c)

    +", "+Math. round (c));

    max = Math. max ((int) 'D',71);

    System. out. println ("The Maximum between D and 71 is " + max);

    Random rand = new Random ();

    int RandValue = rand. nextInt (20);

    System. out. println ("A random Number between 0 and 20 is " + RandValue);

    }

    }

    Explanation:

    In order to get the square root of the number 37, the square root function is called by the statement Math. sqrt (a) since the value 37 has been assigned to a. Method calls are also applied to find the cosine, sine, floor, round and ceiling values for the respective variables.

    To determine the maximum between the character 'D' and the integer 71, we first cast the character 'D' to an integer using this (int) 'D'. Then we make the Method call Math. max ().

    To generate a random variable between 0 and 20, we first make an object of the class Random we use this object to obtain a random number between 0 and 20 by specifying the bound to 20 during the method call.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a Java application that uses the Math class to determine the answers for each of the following: a. The square root of 37 b. The sine ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers