FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-coding-ninjas/recursion1/NumberOfDigit.java at master · avinashbest/java-coding-ninjas · GitHub
avinashbest
/
java-coding-ninjas
Public
Notifications
You must be signed in to change notification settings
Fork
11
Star
18
Code
Issues
0
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-coding-ninjas
/
recursion1
/
NumberOfDigit.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (31 loc) · 799 Bytes
Breadcrumbs
java-coding-ninjas
/
recursion1
/
NumberOfDigit.java
Copy path
File metadata and controls
34 lines (31 loc) · 799 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package
recursion1
;
import
java
.
util
.
Scanner
;
/*Given the code to find out and return the number of digits present in a number recursively. But it contains few bugs, that you need to rectify such that all the test cases should pass.
Input Format :
Integer n
Output Format :
Count of digits
Constraints :
1 <= n <= 10^6
Sample Input 1 :
156
Sample Output 1 :
3
Sample Input 2 :
7
Sample Output 2 :
1*/
public
class
NumberOfDigit
{
public
static
int
numberOfDigit
(
int
n
) {
if
(
n
==
0
) {
return
0
;
}
int
smallAnswer
=
numberOfDigit
(
n
/
10
);
return
smallAnswer
+
1
;
}
public
static
void
main
(
String
[]
args
) {
Scanner
scan
=
new
Scanner
(
System
.
in
);
int
n
=
scan
.
nextInt
();
System
.
out
.
println
(
numberOfDigit
(
n
));
}
}
Back
|
FazBrowse Home
|
New Git URL