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

containsBothDigits

Language/Type: Java method basics mod parameters return
Author: Marty Stepp (on 2010/12/28)

Write a method named containsBothDigits that accepts three integer parameters a, b, and c. Assume that a is a positive integer (greater than 0) and that b and c are single-digit numbers from 0 through 9 inclusive. Your method should return true if a contains both b and c among its digits, and false otherwise.

For example, the number 433407 contains 4, 3, 0, and 7 as its unique digits, so a call of containsBothDigits(433407, 7, 3) should return true. If b and c are the same number, your method should return true if that digit appears at least once among the digits; in other words, the same digit from a could match both b and c. So for example, a call of containsBothDigits(433407, 7, 7) should return true.

The following table shows several other calls to your method and their results:

Call Value Returned Reason
containsBothDigits(12345, 2, 5) true 12345 contains the digits 2 and 5
containsBothDigits(3004955, 3, 0) true 3004955 contains the digits 3 and 0
containsBothDigits(1650, 6, 6) true 12345 contains the digit 6
containsBothDigits(12345, 1, 7) false 12345 does not contain a digit 7
containsBothDigits(42, 4, 7) false 42 does not contain a digit 7

You may not use a String to solve this problem.

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.