SHOW:
|
|
- or go back to the newest paste.
1 | public class SelfDivisorSkel | |
2 | { | |
3 | public static boolean isSelfDivisor(int number) | |
4 | { | |
5 | int digit = 0; | |
6 | int temp = number; | |
7 | while (temp > 0) | |
8 | { | |
9 | digit = temp % 10; | |
10 | if (digit == 0 || number % digit != 0) | |
11 | { | |
12 | return false; | |
13 | } | |
14 | temp /= 10; | |
15 | } | |
16 | return true ; | |
17 | } | |
18 | ||
19 | public static int[] firstNumSelfDivisor(int start, int num) | |
20 | { | |
21 | ||
22 | int[] divisorArr = new int[num]; | |
23 | for (int i = 0; i < divisorArr.length; i++) | |
24 | { | |
25 | while (!(isSelfDivisor(start))) | |
26 | { | |
27 | start++; | |
28 | } | |
29 | divisorArr[i] = start; | |
30 | start++; | |
31 | } | |
32 | return divisorArr; | |
33 | } | |
34 | ||
35 | public static void main(String[]args) | |
36 | { | |
37 | System.out.println(isSelfDivisor(12)); //true | |
38 | System.out.println(isSelfDivisor(10)); //false | |
39 | System.out.println(isSelfDivisor(24)); //true | |
40 | System.out.println(isSelfDivisor(13)); //false | |
41 | ||
42 | //part b | |
43 | System.out.println(firstNumSelfDivisor(10,5)); //represents and array (object), will not print the 3 values you hoped for...will print object reference. | |
44 | ||
45 | ||
46 | ||
47 | System.out.print("Array values: "); | |
48 | ||
49 | //part b | |
50 | for(int i = 0; i < firstNumSelfDivisor(10,5).length; i++) | |
51 | { | |
52 | System.out.print(firstNumSelfDivisor(10,5)[i] + " "); | |
53 | } | |
54 | } | |
55 | } |