• + 1 comment

    You can optimize that one step to the following... to avoid correction for doubble addition, when input number is an exact square.

    public int divisorSum(int n){
           int sum = 0;int i;
           for( i = 1; i <(int)Math.sqrt(n); i++) {
               if(n%i==0){
                   sum = sum + i + n/i;
               }
           }
           if(i*i == n){
               sum = sum+i;
           }
            return sum;
        }