Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

printTwoDigit

Language/Type: Java method basics println Random
Author: Roy McElmurry (on 2010/12/28)

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.

(Because this problem uses random numbers, our test cases check only the general format of your output. You must still examine the output yourself to make sure the answer is correct.)

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.