forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumOfDivisor.java
More file actions
36 lines (33 loc) · 758 Bytes
/
Copy pathSumOfDivisor.java
File metadata and controls
36 lines (33 loc) · 758 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
package com.examplehub.maths;
public class SumOfDivisor {
/**
* Calculate sum of divisors of a number, including itself.
*
* @param number the number to be calculated
* @return sum of divisors.
*/
public static int sumOfDivisorInclude(int number) {
int sum = 0;
for (int i = 1; i <= number; i++) {
if (number % i == 0) {
sum += i;
}
}
return sum;
}
/**
* Calculate sum of divisors of a number, excluding itself.
*
* @param number the number to be calculated
* @return sum of divisors.
*/
public static int sumOfDivisorExclude(int number) {
int sum = 0;
for (int i = 1; i < number; i++) {
if (number % i == 0) {
sum += i;
}
}
return sum;
}
}