Skip to content

Commit aa5f77c

Browse files
committed
finds total number of digits in number using recursion
1 parent 697d3e4 commit aa5f77c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package CodingNinja.recursion;
2+
3+
public class NumberOfDigitsInNumber {
4+
5+
public static int countDigits(int num) {
6+
if (num == 0)
7+
return 0;
8+
9+
int smallerOutput = countDigits(num / 10);
10+
int output = 1 + smallerOutput;
11+
12+
return output;
13+
}
14+
15+
public static void main(String[] args) {
16+
System.out.println(countDigits(12333348));
17+
}
18+
}

0 commit comments

Comments
 (0)