printTwoDigit
Category: Programming
Author: Stuart Reges
Book Chapter: 5.1
Problem: printTwoDigit
Write a static method called printTwoDigit that
takes 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. The method should indicate
whether the number 42 was selected. For example, given the following lines
of code:
Random r = new Random();
printTwoDigit(r, 4);
You would expect output like the following:
next = 52
next = 10
next = 96
next = 86
no 42
As the final line of output above indicates, that particular sequence did
not include the number 42. Suppose that we then call the method as follows:
printTwoDigit(r, 6);
We might get output like the following where 42 is included in the sequence:
next = 83
next = 29
next = 42
next = 22
next = 36
next = 73
We saw a 42
You may assume the integer value passed to your method is greater than or
equal to 0. You are to exactly reproduce the format of these logs. Write
your solution to printTwoDigit below.