You are viewing a single comment's thread. Return to all comments →
Here is my code for Java 15 :
public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); MyCalculator mcal = new MyCalculator(); System.out.println("I implemented: " + mcal.getClass().getInterfaces()[0].getName()); System.out.println(mcal.divisor_sum(a)); } } class MyCalculator implements AdvancedArithmetic { int sum = 0; public int divisor_sum(int n){ for(int i = 1; i<=n ; i++){ if(n%i == 0){ sum +=i; } } return sum; } } interface AdvancedArithmetic { int divisor_sum(int n); }
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 →
Here is my code for Java 15 :