Write a recursive method nmbdigits

Assignment Help Programming Languages
Reference no: EM13188182

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 examplenmbDigits(2054) is 4). Write a driver programTestDigits.javato test the method. Ask the user to enter an integer value then invoke the method passing the entered value as method parameter. 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 programTestMeanVal.javato 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.

meanRec(n) =(a[n-1] + a[n-2] + ... + a[0]) / n

You should organize the right side of the above assignment statement to highlight there the expression ofmeanRec(n-1)which is: (a[n-2] + a[n-3] + ... + a[0]) / (n-1).

Reference no: EM13188182

Questions Cloud

Describe the industrial revolution : 1. began in France with the development of the steam engine and then spread to the UK and the United States. 2. began in 1550 when the English learned how to use coal to replace wood as a heat source and spread to france and eventually the United S..
How long would it take to fill the available storage space : How many cells can be in a computer's main memory if each cell's address can be represented by two hexadecimal digits? What if four hexadecimal digits are used? Explain your answer.
Determine the limit of the sequence or show that sequence : determine the limit of the sequence or show that the sequence diverges by using the appropriate Limit Laws or theorems.
When the worlds population is about to collapse : Almost all of the fossil fuels that we are now currently using were formed during the Carboniferous period.  (b) There seems to be a strong correlation between increases in the availability of food energy per person and increases in human populati..
Write a recursive method nmbdigits : Design and implement meanIter, the iterative version of the method - Write a recursive method nmbDigits which takes an integer value as parameter and returns the number of digits of the parameter value
How much water does it hold one hour later : Water is pumped out of a holding tank at a rate of 6- 6e-0.10t liters/minute, where t is in minutes since the pump is started. If the holding tank contains 1000 liters of water when the pump is started, how much water does it hold one hour later?
Explain a substitutional solid solution with silicon : Germanium forms a substitutional solid solution with silicon. Compute the weight percent of germanium that must be added to silicon to yield an alloy that contains 4.43 × 1021 Ge atoms per cubic centimeter
How much does fred make : Paul makes $25.00 a week less than the sum of what Fred and Carl together make. Carl's weekly income would be triple Steven's if he made $50.00 more a week. Paul makes $285.00 a week and Steven makes $75.00 a week. How much does Fred makE?
Explain the widespread use of slavery : The industrialization period of the late 1800's saw several new forms of energy developed, including 1. more effective use of humans and animals to power machinery using treadmills.

Reviews

Write a Review

Programming Languages Questions & Answers

  Recursive method to read in string of characters

Trying to write a recursive method that reads in a string of characters and checks to see if the first character is either a 'D' or and 'E', then is followed by a string of one or more 'F's.

  Write program to match master and transaction methods

When writing a program to match master and transaction methods, what should happen when the value of the master key is equal to the transaction key?

  Explaining class definition of subclass of square

Write down the class definition of subclass of Square called FancySquare which has a method called getDiagonal. The getDiagonal method gets no arguments.

  Prolog program to reads employee-s number

Write a prolog program that reads an employee's number from the keyboard, number of hours worked and an hourly rate of pay.

  Calculates and displays the property tax

Write a java application that calculates and displays the property tax for N property owners. N should be declared as a constant and it should be equal to the largest digit of your student ID number

  Recursive method to search a string for a byrd

Write a recursive method that searches a string for a Byrd. A Byrd has the following properties. Its first character is an 'A'. If it is a two character Byrd then its second and last character is an 'H'.

  Write a vhdl code for soda vending machine

Write a VHDL code that implements the above soda machine. You have to turn in the following: A state diagram showing the implementation of your design. Clearly show all the states and the conditions on which transitions occur.

  Program to processes the test data

Write a program that processes the test data. The output should be the student's ID, followed by the answers, followed by the test score, and followed by the test grade.

  Design and implement program that creates exception class

Design and implement a program that creates an exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it

  Program to read the contents of file into the array

Write down the program which asks user for a file name. Suppsoe the file contains the series of numbers, each written on separate line.

  Write program to will read unspecified number of positive

Write a program which will read the unspecified number of positive numbers from keyboard and determine the sum and average of these numbers.

  Write program which prints question and reads user input

Write the program which prints question "Do you want to continue?" and reads user input. If user input is "Y", "Yes", "OK", "Sure", or "Why not?", print out "OK".

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd