Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 12 Weeks Ago, 3 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
Using Java....
1: Write a java program that use the factorial recursive method to
A) Accept factorial number from keyboard.
B) Validate the input. Reject the invalid input until the input is accepted. (Reject input if it is character or string)
C) Use recursive call to calculate the factorial value.
D) Print the result
E) Accept the next number until terminated by user. (enter 0)
*** Write a class object to do the factorial calculation instead of method in the main program. ***
2: Do the similar program for power function by using two recursive methods. Compare two methods we addressed in the lecture. (display the CPU time for both methods)
3: The “odd/even factorial” of a positive integer is represented as n!! and is defined non-recursively as: (n)(n-2)(n-4)…(4)(2) if n is even and is (n)(n-2)(n-4)…(5)(3)(1) if n is odd. For example 7!! Equals 7*5*3*1 or 105 and 6!! Is 6*4*2 or 48. Write a method called oddevenfact that recursively calculates the odd/even factorial value of its single int parameter. The value returned by this method is a long. Validate the input.
*** Write a class object to do the Oddeven factorial calculation instead of method in the main program. **