- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
Latest commit
41 lines (35 loc) · 1.11 KB
/
Copy pathSolution.java
File metadata and controls
41 lines (35 loc) · 1.11 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
importjava.util.*;
interfaceAdvancedArithmetic {
intdivisor_sum(intn);
}
classMyCalculatorimplementsAdvancedArithmetic {
@Override
publicintdivisor_sum(intn) {
intsum = n;
for (inti = 1; i <= n / 2; i++) {
if (n % i == 0) sum += i;
}
returnsum;
}
}
classSolution {
publicstaticvoidmain(String[] args) {
MyCalculatormy_calculator = newMyCalculator();
System.out.print("I implemented: ");
ImplementedInterfaceNames(my_calculator);
Scannersc = newScanner(System.in);
intn = sc.nextInt();
System.out.print(my_calculator.divisor_sum(n) + "\n");
sc.close();
}
/*
* ImplementedInterfaceNames method takes an object and prints the name of the interfaces it implemented
*/
staticvoidImplementedInterfaceNames(Objecto) {
Class[] theInterfaces = o.getClass().getInterfaces();
for (inti = 0; i < theInterfaces.length; i++) {
StringinterfaceName = theInterfaces[i].getName();
System.out.println(interfaceName);
}
}
}