-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumDigits.java
More file actions
89 lines (75 loc) · 1.33 KB
/
Copy pathSumDigits.java
File metadata and controls
89 lines (75 loc) · 1.33 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package testReview;
public class SumDigits {
public static void main(String[] args) {
System.out.println(sumOfDigits(3451));
System.out.println(recur(1));
System.out.println(recur(4));
printFun(3);
System.out.println();
for (int i = 0; i < 21; i++)
{
System.out.println(checkPrime(i, 2));
}
}
private static int sumOfDigits(int i)
{
if (i < 10)
{
return i;
}
else
{
return (i % 10) + sumOfDigits((i/10));
}
}
private static double recur(double term)
{
double result = 0;
if (term > 1)
{
result = (recur(term - 1)*term*2 + 3);
}
else
{
result = 1;
}
return result;
}
private static void printFun(int test)
{
if (test < 1)
{
return;
}
else
{
System.out.print(test + " ");
printFun(test - 1);
System.out.print(test + " ");
return;
}
}
private static boolean checkPrime (int num, int divisor)
{
if (num == 0)
{
return false;
}
else if(num == 1)
{
return false;
}
else if (divisor == num)
{
return true;
}
else if ((num % divisor) == 0)
{
return false;
}
else
{
return checkPrime(num, divisor + 1);
}
}
}