-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivisorDigits .java
More file actions
55 lines (52 loc) · 1.25 KB
/
Copy pathDivisorDigits .java
File metadata and controls
55 lines (52 loc) · 1.25 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Problem Statement
Create a class DivisorDigits containing a method howMany which takes an int number and returns how many digits in number divide evenly into number itself.
Definition
Class:
DivisorDigits
Method:
howMany
Parameters:
int
Returns:
int
Method signature:
int howMany(int number)
(be sure your method is public)
Notes
-
No number is divisible by 0.
Constraints
-
number will be between 10000 and 999999999.
Examples
0)
12345
Returns: 3
12345 is divisible by 1, 3, and 5.
1)
661232
Returns: 3
661232 is divisible by 1 and 2.
2)
52527
Returns: 0
52527 is not divisible by 5, 2, or 7.
3)
730000000
Returns: 0
Nothing is divisible by 0. In this case, the number is also not divisible by 7 or 3.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
*/
public class DivisorDigits {
public int howMany(int number){
int count = 0;
String data = Integer.toString(number);
for (int i = 0; i < data.length(); i++){
if(((int)(data.charAt(i)) - 48 > 0) && number % (int)(data.charAt(i) - 48) == 0) {
count++;
}
}
return count;
}
}