Skip to content

Commit d5dbfda

Browse files
authored
Create NumberOfDigits.java
1 parent 56fbc5a commit d5dbfda

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Given the code to find out and return the number of digits present in a number recursively.
3+
4+
Input Format :
5+
Integer n
6+
7+
Output Format :
8+
Count of digits
9+
10+
Constraints :
11+
1 <= n <= 10^6
12+
13+
Sample Input 1 :
14+
156
15+
Sample Output 1 :
16+
3
17+
18+
Sample Input 2 :
19+
7
20+
Sample Output 2 :
21+
1
22+
*/
23+
24+
public class NumberOfDigits {
25+
26+
public static int count(int n){
27+
if(n == 0){
28+
return 0;
29+
}
30+
int smallAns = count(n / 10);
31+
return smallAns+1;
32+
}
33+
34+
}

0 commit comments

Comments
 (0)