• 100% Satisfaction Guarantee
John, Engineer
Category: Homework
Satisfied Customers: 798
Experience:  Bachelors Degree
27270878
John is online now

# Question 1Write a recursive method nmbDigits which takes

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.
hi

when is due this
Customer: replied 3 years ago.

In less than 30 minutes.

hi

only 30 mts,
Customer: replied 3 years ago.

Yes.

hi

ok
Customer: replied 3 years ago.

Thanks. Let me know if you need any other information.

hi

not yet
Customer: replied 3 years ago.

Ok

HI

My name is John

http://ge.tt/7Pv00Sw/v/0
http://ge.tt/6uaF0Sw/v/0

Hope this helps

If you need any changes, ask me before rating this ,Otherwise rate my answer as "Excellent"

John, Engineer
Category: Homework
Satisfied Customers: 798
Experience: Bachelors Degree
Customer: replied 3 years ago.

Hi, can you tell me how to add a message if the user doesn't enter an integer value in TestDigits.java? Thanks.

Wait