Java Reference
In-Depth Information
REVIEW EXERCISES
΢΢Exercise R4.1. Write the following mathematical expressions in Java.
1
2 gt 2
s =
s 0
+ t +
v 0
a 3
G = 4Ǡ 2
( m 1
m 2 )
p 2
+
100 ) YRS
(
INT
FV =PV – 1 +
a 2
b 2
c =
+
ɨ 2ab cos Ǔ
171
172
΢΢Exercise R4.2. Write the following Java expressions in mathematical
notation.
a. dm = m * (Math.sqrt(1 + v / c) / (Math.sqrt(1
- v / c) - 1)) ;
b. volume = Math.PI * r * r * h ;
c. volume = 4 * Math.PI * Math.pow(r, 3) / 3 ;
d. p = Math.atan2(z, Math.sqrt(x * x + y * y)) ;
΢΢΢Exercise R4.3. What is wrong with this version of the quadratic formula?
x1 = (-b - Math.sqrt(b * b - 4 * a * c)) / 2 * a;
x2 = (-b + Math.sqrt(b * b - 4 * a * c)) / 2 * a;
΢΢Exercise R4.4. Give an example of integer overflow. Would the same
example work correctly if you used floating-point?
΢΢Exercise R4.5. Give an example of a floating-point roundoff error. Would
the same example work correctly if you used integers and switched to a
sufficiently small unit, such as cents instead of dollars, so that the values
don't have a fractional part?
΢΢Exercise R4.6. Consider the following code:
Search WWH ::




Custom Search