Exercise 2.6
- State the value and type of each expression.
- Math.abs(-S)-Math.abs(-7)
- Math.abs(-1e-1) + Math.abs(-2e-2)
- Math.sqrt(0.0064)
- Math.sqrt(Math.pow(2.7,2)
- Math.round(3.499)
- Math.max(1.5e-2,0.095)
- Math.ceil(4.002)
- Math.min(-5,1.0)
- Math.floor(7.99)
- Math.ceil(-2.73)
- Math.pow(16,O.25)
- Math.pow(4,-2)
- Math.round(1.49 + 0.1)
- Math.round(1.49) + 0.1
- Write as Java expressions.

- π(x6 - y6)
- 4/3π r3
- |z4-1|
- ln |1+x|
- x2ex
- A student incorrectly attempted to produce a random value uniformly
distributed over the set {1,2,...,6} using the expression
6*(int)Math.random() + 1
- Write a statement that will make the int variable result take on a
random value uniformly distributed over the given set.
- {1, 2, 3, , 10}
- {1, 2, 3, , 52}
- {5, 10, 15, , 100}
- {-5, -4, -3, , 5}
- {100, 110, 120, , 300}
- {a, a + b, a + 2b,..., a + kb} where a, b, and k are integers.
- Write a statement that will assign the char variable randChoice a
random value from the set {'A', 'B', 'C', 'D', 'E'}.
- Write a statement that will assign the double variable randVal a
random value from the set {1.00, 1.25, 1.50, ... , 4.00}.
- Write a statement that will assign the int variable dodecaRoll
a random value that could result from the rolling of a fair twelvefaced
die with faces numbered from one to twelve.
- Write a statement that will assign the int variable doubleRoll
a random value that could result from noting the sum obtained
by rolling a pair of standard, fair dice with faces numbered from
one to six.
- Find the value of each expression.
- Math.sin(Math.PI/6)
- Math.cos(Math.PI/3)
- Math.cos(0)
- Math.atan(0)
- Math.tan(Math.atan(0.5))
- Math.asin(Math.sin(1))
- Write Java expressions for each of the following.
- sin 45°
- cos 120°
- tan 24°
- sec 18°
- csc l60°
- cot 15°
- arctan 2
- arcsin 0.5

- sec-1(1.5)
- Write an expression that could be used to find the value of log10x.
- In this section, we showed a program that rounded a value to the
nearest hundredth. How would that program have to be modified to
round values to
- the nearest tenth?
- the nearest thousand?
- Airport runways are often given numbers determined by the direction
in which planes travel as they move along the runways. The number
of a runway is found by taking the bearing in degrees (to the nearest
ten degrees) and dropping the final zero. For example, a runway with
a bearing between 265° and 275° would have a runway number of 27.
Write a program that asks the user for a bearing (from 0° to 360°)
and then determines the corresponding runway number.
- Write a program that asks for a length of time in hours and then converts
this measurement to hours, minutes, and seconds. For example,
input of 38.47 should produce output similar to the following:
|
|