-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.java
More file actions
33 lines (28 loc) · 865 Bytes
/
interfaces.java
File metadata and controls
33 lines (28 loc) · 865 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
import java.io.*;
import java.util.*;
interface AdvancedArithmetic{
int divisorSum(int n);
}
//Write your code here
class Calculator implements AdvancedArithmetic{
Calculator(){
}
public int divisorSum(int n){
int sum = n;
for (int i = 1, half = n/2; i <= half; i++) {
if (n % i == 0) sum += i;
}
return sum;
}
}
class Solution {
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);
}
}