Write a recursive Java method that takes a non-negative integer as a parameter and returns the number of digits it contains. For example the integer 45678 has five digits so the method will return the number 5. The process involves dividing the integer by 10 to shift the number by one position until the integer is less than 10. The first case when the integer is less than 10 will return 1. Write an iterative implementation of the method as well. Test both methods in a program.
Write a recursive Java method that takes a non-negative integer as a parameter and returns the number of digits it contains. For example the integer 45678 has five digits so the method will return the number 5. The process involves dividing the integer by 10 to shift the number by one position until the integer is less than 10. The first case when the integer is less than 10 will return 1. Write an iterative implementation of the method as well. Test both methods in a program.
Attachments: