Write a recursive method called digitCount() that takes a positive integer as a parameter and returns the number of digits in the integer. Hint: The number of digits increases by 1 whenever the input...



Write a recursive method called digitCount() that takes a positive integer as a parameter and returns the number of digits in the integer. Hint: The number of digits increases by 1 whenever the input number is divided by 10. Use Java.




Ex: If the input is:


345



the method digitCount() returns and the program outputs:


3



import java.util.Scanner;


public class LabProgram {


/* TODO: Write recursive digitCount() method here. */


public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int num, digits;


num = scnr.nextInt();
digits = digitCount(num);
System.out.println(digits);
}
}




Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here