Java Software Solutions, 8e, Global Edition
Exercise Solutions, Ch. 3
e. generator.nextInt(100) – 50
EX 3.8. Write code to declare and instantiate an object of the Random class (call the
object reference variable rand). Then write a list of expressions using the
nextInt method that generate random numbers in the following specified
ranges, including the endpoints. Use the version of the nextInt method that
accepts a single integer parameter.
a. 0 to 10
b. 0 to 400
c. 1 to 10
d. 1 to 400
e. 25 to 50
f. –10 to 15
EX 3.9. Write an assignment statement that computes the square root of var1,
subtracts it from var2 and assigns the result to var3.
EX 3.10. Write a single statement that computes and prints the fifth power of sum.
EX 3.11. Write code statements to create a DecimalFormat object that will round a
formatted value to 4 decimal places. Then write a statement that uses that object
to print the value of result, properly formatted.
EX 3.12. Write code statements that prompt for and read a double value from the user,
and then print the result of raising that value to the fourth power. Output the
results to 3 decimal places.