We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
class Calculator implements AdvancedArithmetic {
public int divisorSum(int n) {
int sum=n;
int i=1;
while(i<=n/2){
if(n%i==0)
sum+=i;
i++;
}
return sum;
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 19: Interfaces
You are viewing a single comment's thread. Return to all comments →
here is my simple and optimized code:
class Calculator implements AdvancedArithmetic { public int divisorSum(int n) { int sum=n; int i=1; while(i<=n/2){ if(n%i==0) sum+=i; i++; } return sum; } }