Day 19: Interfaces | 30 Days of Coding | HackerRank | Java Languag

**Before watching this make sure that you’ve tried enough**
Language: Java 7

import java.util.*;

interface AdvancedArithmetic{
   int divisorSum(int n);

//Write your code here

class Calculator implements AdvancedArithmetic{
    int sum = 0;
    public int divisorSum(int n){
        for(int i = 1;i <= n;i++){
            if(n%i == 0) sum += i;
        return sum;
class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(;
        int n = scan.nextInt();
      	AdvancedArithmetic myCalculator = new Calculator(); 
        int sum = myCalculator.divisorSum(n);
        System.out.println("I implemented: " + myCalculator.getClass().getInterfaces()[0].getName() );


If this solution helped you, please share this with your friends.
And if you have anything to say, let me know in the comment section.
More solutions are coming so Like our Facebook page and Subscribe to our YouTube channel to stay connected.

Leave a Comment