Write a program to find the number of digits in a number using recursion.
Input and Output Format:
Input consists of a nonnegative integer.
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.
Sample Input and Output:
Enter the value of n
432
The number of digits in 432 is 3
Solution
import java.util.*;
public class Main {
public static void main(String[] args)
{
int n;
System.out.println("Enter the value of n");
Scanner s = new Scanner(System.in);
n = s.nextInt();
System.out.println("The number of digits in " + n + " is " + (findnum(n / 10)));
}
public static int findnum(int n) {
if (n == 0)
{
return 1;
} else {
return (+findnum(n / 10));
}
}
}Happy Learning – If you require any further information, feel free to contact me.
![[Solved] Number of digits with Java [Solved] Number of digits with Java](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Number-of-digits-with-Java.png)
![[Solved] RILED String with Java](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-RILED-String-with-Java-300x200.png)
![[Solved] Design a way to sort the list of positive integers in the descending order according to frequency of the elements](https://realcoder.techss24.com/wp-content/uploads/2022/11/Solved-Design-a-way-to-sort-the-list-of-positive-integers-in-the-descending-order-according-to-frequency-of-the-elements-300x197.png)
