logo Practice-It logo

BJP4 Exercise 5.22: allDigitsOdd

Language/Type: Java method basics mod return while loops
Author: Marty Stepp (on 2016/09/08)

Write a method named allDigitsOdd that returns whether every digit of a given integer is odd. Your method should return true if the number consists entirely of odd digits and false if any of its digits are even. 0, 2, 4, 6, and 8 are even digits, and 1, 3, 5, 7, 9 are odd digits. Your method should work for positive and negative numbers.

For example, here are some calls to your method and their expected results:

Call Value Returned
allDigitsOdd(4822116) false
allDigitsOdd(135319) true
allDigitsOdd(9175293) false
allDigitsOdd(-137) true

You should 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.