Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.

Get a Professional Answer

Via email, text message, or notification as you wait on our site. Ask follow up questions if you need to.

100% Satisfaction Guarantee

Rate the answer you receive.

Ask John Your Own Question

John, Engineer

Category: Homework

Satisfied Customers: 798

Experience: Bachelors Degree

27270878

Type Your Homework Question Here...

John is online now

Question 1Write a recursive method nmbDigits which takes

This answer was rated:

★★★★★

Question 1

Write a recursive method nmbDigits which takes an integer value as parameter and returns the number of digits of the parameter value (for example nmbDigits(2054) is 4). Write a driver program TestDigits.java to test the method. In the driver program, ask the user to enter an integer value, invoke the method (passing the entered value as parameter) and display the result. Note. If an illegal value is entered, a message should be shown and the user will be required to enter a correct value.

Hint: Divide the number by 10 and count for how many times you can do that.

Question 2

Consider a method which calculates and returns the arithmetic mean of an array of integer values.

a) Design and implement meanIter, the iterative version of the method.

b) Design and implement meanRec, the recursive version of the method.

c) Write a driver program TestMeanVal.java to test the two methods. Consider an array of size 20 populated with random integer values in the range 1 .. 99. Invoke the two methods and display the result.

Hint: For the recursive method, try to deduce a recurrence relation between meanRec(n) and meanRec(n-1). Start from meanRec(n) formula (consider an array a of size n) meanRec(n) = (a[n-1] + a[n-2] + … + a[0]) / n and organize the right side of the above assignment statement to highlight there the expression of meanRec(n-1) which is: (a[n-2] + a[n-3] + ... + a[0]) / (n-1).

Submission requirements Your completed assignment consist of the TestDigits.java and TestMeanVal.java files.

For your future questions , Please post your questions starting with "For John" If you need any changes, ask me before rating this ,Otherwise rate my answer as "Excellent"