-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselfDivisor.java
More file actions
69 lines (61 loc) · 955 Bytes
/
Copy pathselfDivisor.java
File metadata and controls
69 lines (61 loc) · 955 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
public class selfDivisor
{
private static boolean isSelfDivisor(int number)
{
while(number > 0)
{
if(number%10 == 0)
{
return false;
}
else if(number%(number%10) == 0)
{
number/=10;
}
else
{
return false;
}
}
return true;
}
private static int[] firstNumSelfDivisors(int start, int num)
{
int[]SelfDiv = new int[num];
int pos = 0;
int i = start;
while(i>=start)
{
if(isSelfDivisor(i) == true)
{
if(pos<num)
{
SelfDiv[pos] = i;
pos++;
i++;
}
else
{
break;
}
}
else
{
i++;
}
}
return SelfDiv;
}
public static void display(int []num)
{
for(int i = 0; i<num.length; i++)
{
System.out.print(num[i] + " ");
}
}
public static void main(String[]args)
{
System.out.println(isSelfDivisor(10));
display(firstNumSelfDivisors(10,3));
}
}