-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay19.java
More file actions
32 lines (27 loc) · 790 Bytes
/
Day19.java
File metadata and controls
32 lines (27 loc) · 790 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
package HackerRank.CodingDays30;
import java.util.Scanner;
interface AdvancedArithmetic{
int divisorSum(int n);
}
class Calculator implements AdvancedArithmetic {
public int divisorSum(int n) {
int num = 0;
for (int i = 1; i<=n; i++) {
if (n % i == 0) {
num += i;
}
}
return num;
}
}
public class Day19 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.close();
AdvancedArithmetic myCalculator = new Calculator();
int sum = myCalculator.divisorSum(n);
System.out.println("I implemented: " + myCalculator.getClass().getInterfaces()[0].getName() );
System.out.println(sum);
}
}