-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelfDividing.java
More file actions
43 lines (34 loc) · 899 Bytes
/
SelfDividing.java
File metadata and controls
43 lines (34 loc) · 899 Bytes
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
package Math;
import java.util.LinkedList;
import java.util.List;
/**
* Author - archit.s
* Date - 15/08/18
* Time - 10:24 PM
*/
public class SelfDividing {
private boolean isDiviisble(int input){
int original = input;
boolean flag = false;
while (input != 0){
int temp = input%10;
input /= 10;
if(temp == 0 || original%temp != 0){
return false;
}
}
return true;
}
public List<Integer> selfDividingNumbers(int left, int right) {
List<Integer> result = new LinkedList<>();
for (int i = left; i <= right; i++) {
if(isDiviisble(i)){
result.add(i);
}
}
return result;
}
public static void main(String[] args) {
System.out.println(new SelfDividing().selfDividingNumbers(1, 22));
}
}