You are viewing a single comment's thread. Return to all comments →
interface AdvancedArithmetic{ int divisor_sum(int n); } class MyCalculator implements AdvancedArithmetic{ public int divisor_sum(int n){ int result = n; int num = n/2; while (num>0){ if (n % num == 0 ) result += num; num--; } return result; } } public class Solution { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); MyCalculator cal = new MyCalculator(); int solution = cal.divisor_sum(n); System.out.println("I implemented: " + cal.getClass().getInterfaces()[0].getSimpleName()); System.out.print(solution); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Interface
You are viewing a single comment's thread. Return to all comments →