Java TOPIC 10 – MATH FUNCTIONS LESSON WORK QUESTION 1 Answer the
following questions. a)
What
does API stand for? b)
What
is the URL for Java’s API? (Use Google
to find it.) c)
In
the Math class, there is a max function.
What does it do? d)
Which
Math class function can be used to round a number up? e)
Which
Math class function can be used to round a number down? f)
What
is the absolute value of a number?
There is a function for this. g)
What
is a function prototype (also known as a method prototype)? Save your
work inside the file Question01.txt
in the topic10 folder. QUESTION 2 (SELF-CHECK) Use Java’s
Math function to write the following statements inside a Java program: a)
a
= squareroot of 101 b)
b
= 55 c)
c
= a2 + b2 d)
d
= rounded value of a e)
e
= integer value of a f)
f
= random decimal number between 0 and 1 g)
g
= cube root of 81 h)
i)
i = 2(d + 3) j)
j
= 1000.5 * 25 k)
k
= absolute value of -4 To verify the
answers, you could make your program output to screen the value of each
variable.
QUESTION
3 What value will the variable get? a) int a =
Math.abs(-25); b) double b =
Math.ceil(7.9); c) double c =
Math.pow(2,4); d) int d =
Math.min(-3, 2); e) double e =
Math.pow(Math.min(2,4), Math.max(1,2)); f) double f =
28 / 7 * Math.abs(4); g) double g =
Math.pow(Math.pow(2,2),3); h) double h =
Math.min(Math.pow(2,3),Math.pow(2,Math.max(1,2))); i) double i =
Math.PI * 2; j)
double j =
Math.abs(Math.min(-3, 2)); Save your
work inside the file Question03.txt
in the topic10 folder. QUESTION
4 Inside a program called Randomness.java, do the following: a) Write a
statement that generates a random number between 0 and 1. Output the number to screen. Test your program. b) Write
another statement that generates a random number between 0 and 10. Output the number to screen. Test your program. c) Write
another statement that generates a random whole number between 0 and 10. Output the number to screen. Test your program. d) Write
another statement that generates a random whole number between 5 and 15. Output the number to screen. Test your program. In the end, your program should be generating 4 random numbers each
time that it is ran. Save your program insde the topic10 folder. QUESTION
5 Write a program that asks the user to input two different numbers. The program simply outputs the largest
number of the two. Look up the max
function. Save your
work inside a Largest.java file
inside the topic10 folder. |
|