Question: a. Write a function named countDigits that accepts a positive integer as its parameter and returns the number of digits in that number. For example,

 a. Write a function named countDigits that accepts a positive integer

a. Write a function named countDigits that accepts a positive integer as its parameter and returns the number of digits in that number.

For example, the number 8546587 has seven digits, so the call countDigits(8546587) should return 7.

You may assume that the value passed to your method is non-negative.

b. Write a program to input an integer n and call the above function in part a if n is positive, else give Value must be Positive message. Inputting will stop when 0 is entered.

a. Write a function named countDigits that accepts a positive integer as its parameter and returns the number of digits in that number. For example, the number 8546587 has seven digits, so the call countDigits(8546587) should return 7. You may assume that the value passed to your method is non-negative. b. Write a program to input an integer n and call the above function in part a if n is positive, else give 'Value must be positive' message. Inputting will stop when 0 is entered. Sample Run: Enter an integer (0 to stop): 1046 1046 has 4 digits Enter an integer (o to stop): 8712013 8712013 has 7 digits Enter an integer (0 to stop): -23 Value must be positive Enter an integer (o to stop) : 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!