EX 3.7 Assuming that a Random object has been created called generator, what is
ID: 3832400 • Letter: E
Question
EX 3.7 Assuming that a Random object has been created called generator, what is the range of the result of each of the following expressions?
a. generator.nextInt(20)
b. generator.nextInt(8) + 1
c. generator.nextInt(12) + 2
d. generator.nextInt(35) + 10
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 generates 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 four 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 three decimal places.
EX 3.13 Write a declaration for an enumerated type that represents the months of the year.
Explanation / Answer
EX 3.7 Assuming that a Random object has been created called generator, what is the range of the result of each of the following expressions?
a. generator.nextInt(20) : 0 - 19
b. generator.nextInt(8) + 1 : 1-8
c. generator.nextInt(12) + 2 :: 2-13
d. generator.nextInt(35) + 10 :: 10-44
e. generator.nextInt(100) 50 :: -50-49
=========================================================================
a. 0 to 10:: generator.nextInt(11)
b. 0 to 400:: generator.nextInt(401)
c. 1 to 10:: generator.nextInt(10) + 1
d. 1 to 400:: generator.nextInt(400) + 1
e. 25 to 50:: generator.nextInt(26) + 25
f. -10 to 15:: generator.nextInt(26) - 10
==============================================================================
EX 3.9 Write an assignment statement that computes the square root of var1, subtracts it from var2 and assigns the result to var3.
double var3 = var2 - Math.sqrt(var1);
================================================================================
EX 3.10 Write a single statement that computes and prints the fifth power of sum.
double ans = Math.pow(sum,5);
==================================================
EX 3.13 Write a declaration for an enumerated type that represents the months of the year.
public enum Month { JANUARY, FEBRUARY, MARCH, APRIL, MAY,JUNE, JULY, AUGUST, SEPTEMBER,OCTOBER, NOVEMBER, DECEMBER }
======================================================
Thanks, let me know if there is any concern.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.