File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
src/main/java/HackerRank/thirtyDaysOfCode Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ package hackerRank .thirtyDaysOfCode ;
2+
3+ import java .util .*;
4+
5+ // Interfaces
6+ interface AdvancedArithmetic {
7+ int divisorSum (int n );
8+ }
9+
10+ class Calculator implements AdvancedArithmetic {
11+
12+ @ Override
13+ public int divisorSum (int n ) {
14+ int sum = 0 ;
15+ for (int i = 1 ; i <= n / 2 ; i ++) {
16+ if (n % i == 0 ) {
17+ sum += + i ;
18+ }
19+ }
20+ return sum + n ;
21+ }
22+ }
23+
24+ class Day_19 {
25+ public static void main (String [] args ) {
26+ Scanner scan = new Scanner (System .in );
27+ int n = scan .nextInt ();
28+ scan .close ();
29+
30+ AdvancedArithmetic myCalculator = new Calculator ();
31+ int sum = myCalculator .divisorSum (n );
32+ System .out .println ("I implemented: " + myCalculator .getClass ().getInterfaces ()[0 ].getName ());
33+ System .out .println (sum );
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments