Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the method RECURSIVE productOfDigits() that computes the product of the digits of the given positive integer argument, n, except any digits that are 0.

Complete the method RECURSIVE productOfDigits() that computes the product of the digits of the given positive integer argument, n, except any digits that are 0. Note: productOfDigits() should return always return a non-zero answer since it will only be called with non-zero arguments and 0 digits are ignored. e.g., if n = 5403, the method will return: 5*4*3 = 60 (the 0 was ignored) note: the right-most (1's) digit of a positive integer, n, can be found using n%10 (5403 % 10 is 3, for example) the remaining digits (all but the 1's digit) can be found using n/10 (5403 / 10 is 540, for example) So use a recursive call to get the product of all the other digits and multiply it to the last digit if it's not a 0. The base case is when the number is only one digit, so a recursive call would not be needed.

//testing productOfDigits()

System.out.println(productOfDigits(412));

System.out.println(productOfDigits(2000056));

System.out.println(productOfDigits(90));

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

3. What are potential solutions?

Answered: 1 week ago