1. Mark what is covered and what is not covered in Chapter 8:
2-4.
2. Write a method named ex24 for computing the cubic root of the sum of two given real numbers x and y. Hint: a cubic root of a number z is equal to the number z raised to the power 1/3.
3. Call your method ex24 in the main method to compute the cubic root of a + b, where a = 3.0 and b = 5.0. (You do not need to write the entire main method, just the part that assigns values to a and b and calls your method.)
4. Trace, step by step, how the computer will perform the needed computations, and check that the result is indeed correct.
Solution:
public double ex24(double x, double y){
double z = x + y;
return Math.pow(z,1.0/3.0);}
in the method main:
double a = 3.0;
double b = 5.0;
double c = ex24(a,b);
Tracing:
first,
--------- ---------
| 3.0 | | 5.0 |
--------- ---------
a b
------------------------
| -------- --------- |
| | 3.0 | | 5.0 ||
| -------- --------- |
| x y |
|------------------------|
| ---------- |
| | 8.0 | |
| ---------- |
| z |
------------------------
ex24
---------
| 2.0 |
---------
c