Can anyone please explain the question

gnanagowthaman sankar
gnanagowthaman sankar used Ask the Experts™
on
Given a non-negative int n, compute recursively (no loops) the count of the occurrences of 8 as a digit, except that an 8 with another 8 immediately to its left counts double, so 8818 yields 4. Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12).


count8(8) → 1
count8(818) → 2
count8(8818) → 4
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Are you looking for help understanding the question, or help coding a solution?


»bp
understanding question
SysAdmin
Commented:
As I read it, create a function called count8 that will return the number of 8s in a given positive number.
Keeping in mind that an 8 followed by another 8 will count as double.
Bill PrewIT / Software Engineering Consultant
Top Expert 2016
Commented:
The question is pretty straight forward, look at a string and count all '8' in the string.  If an 8 has an 8 to its left, then count it twice.

The challenge is to do this as a recursive function approach, rather than an iterative loop approach.  If you aren't comfortable with the difference you might look here:

Iteration vs. Recursion in Java


»bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial