0
public static Boolean parfait(Integer k) {
    Integer s = 0;
    for (Integer i = 1; i < k; i++) {
        if (k % i == 0) {
            s=s+i;
            System.out.println(i);
            //return true;
        }
    }
    System.out.println("sum:"+s);
    System.out.println("val:"+k);
    if(s==k){// why 496 != 496
        return true;
    }else{
        return false;
    }
}
System.out.println("Nombre parfait: " + parfait(496));

We make the sum of its positive divisors and we try to check if this number is perfect. With the number 6 and 28 it works perfect but it isn't with other perfect digits like 496 or 8128. Event if we have sum of this divisors which is equal number in parameter it returns false.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578

0 Answers0