0 Replies - 345 Views - Last Post: 02 August 2010 - 10:19 AM

#1 bcranger   User is offline

  • D.I.C Lover
  • member icon

Reputation: 253
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Perfect Number Checker

Posted 02 August 2010 - 10:19 AM

Description: Copy & paste the class. Use the isPerfectNumber() method.Checks to see if a number is a perfect number.
public class PerfectNumberChecker
{
  
  public static boolean isPerfectNumber(int n)
  {
    int sum = 0;
    
    for(int i = 1; i <= n / 2; i++)
    {
      if(n / i == n / (double) i)
        sum += i;
    }
    
    return (n == sum);
  }
  
}

Is This A Good Question/Topic? 0
  • +

Page 1 of 1