Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 9 Weeks Ago, 6 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Assignment 7 • Write a recursive program that calculates m to the nth power. Instead of iteratively multiplying m n times, you will compute the result recursively by performing successive multiplication operations.
• Your program must obtain the numbers m and n from the command line.
• The name of the class you will write to implement this program is Recursive. The main method of this class processes the command line arguments and then calls a method, mToTheNth(), that uses recursion to compute the power. The declaration for the method mToTheNth() is given below: public static int mToTheNth(int m, int n)
ï‚— If n is 0, the result is 1 and the method returns. Otherwise, if n is not 0, compute the result by multiplying m by the result of calling mToTheNth with m and n-1.
ï‚— Expected output: >> java Recursive 2 0 >> 1 >> java Recursive 10 2 >> 100
ï‚— Option: Instead of using command line arguments, you can ask users to type in values for m and n.
Â
Assignment 7•Write a recursive program that calculates m to the nthpower. Instead of iteratively multiplyingm n times, you will compute the result recursively by performing successive multiplicationoperations.•Your program must obtain the numbers m and n from the command line.•The name of the class you will write to implement this program isRecursive. Themainmethod of this class processes the command line arguments and then calls a method,mToTheNth(), that uses recursion to compute the power. The declaration for the methodmToTheNth()is given below:public static int mToTheNth(int m, int n)