-
Notifications
You must be signed in to change notification settings - Fork 855
/
Day19Interfaces.java
46 lines (40 loc) · 1.16 KB
/
Day19Interfaces.java
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
41
42
43
44
45
46
/**
*
* Problem Statement-
* [Interfaces](https://www.hackerrank.com/challenges/30-interfaces/problem)
*
*/
package com.javaaid.hackerrank.solutions.thirtydaysofcode;
import java.util.Scanner;
/**
* @author Kanahaiya Gupta
*
*/
interface AdvancedArithmetic{
int divisorSum(int n);
}
//renamed Calculator class to Calculator2 class as its already present in Day17 question
class Calculator2 implements AdvancedArithmetic{
public int divisorSum(int n){
if(n==1)return 1;
int sum=1+n,r=0;
for(int i=2;i<n;i++){
r=n%i;
if(r==0){
sum=sum+i;
}
}
return sum;
}
}
public class Day19Interfaces {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.close();
AdvancedArithmetic myCalculator = new Calculator2();
int sum = myCalculator.divisorSum(n);
System.out.println("I implemented: " + myCalculator.getClass().getInterfaces()[0].getName() );
System.out.println(sum);
}
}