Solved

Programming
Write a Static Method Named PrintTwoDigit That Accepts a Random

Question 7

Essay

Programming
Write a static method named printTwoDigit that accepts a Random object and an integer n as parameters and that prints a series of n randomly generated two-digit numbers. The method should use the Random object to select numbers in the range of 10 to 99 inclusive where each number is equally likely to be chosen. After displaying each number that was produced, the method should indicate whether the number 42 was ever selected ("we saw a 42!") or not ("no 42 was seen."). You may assume that the value of n passed is at least 0.
The following table shows two sample calls and their output:
 Call  Random r= new Random (); print TwoDigit (r,4); Random r= new Random ( ):  Orint TwoDigit (r,7); Output  next =52 next =83 next =10 next =29 next =96 next =42 next =86 next =22 no 42 was seen.  next =91 next =36 next =73 we saw a 42!\begin{array}{l|l|l}\text { Call } & \begin{array}{l}\text { Random } r=\text { new Random }() ; \\\text { print TwoDigit }(r, 4) ;\end{array} & \begin{array}{l}\text { Random } r=\text { new Random ( ): } \\\text { Orint TwoDigit }(r, 7) ;\end{array} \\\hline \text { Output } & \text { next }=52 & \text { next }=83 \\&\text { next }=10 & \text { next }=29 \\&\text { next }=96 & \text { next }=42 \\&\text { next }=86 & \text { next }=22 \\&\text { no } 42 \text { was seen. } & \text { next }=91 \\& & \text { next }=36 \\&&\text { next }=73 \\& & \text { we saw a } 42 !\end{array}

Correct Answer:

verifed

Verified

(one solution shown)
public static void ...

View Answer

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents