You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1.2 KiB

Perfect Number

Instructions

Write a program to check if a given number is a perfect number. A perfect number is a positive integer that is equal to the sum of its proper positive divisors, excluding itself.

Expected Class

public class PerfectNumber {
    public boolean isPerfectNumber(int number) {
        // Implementation to check if the given number is a perfect number
    }
}

Usage

Here is a possible ExerciseRunner.java to test your class:

public class ExerciseRunner {
    public static void main(String[] args) {
        PerfectNumber perfectNumber = new PerfectNumber();

        int number1 = 6;
        System.out.println("Is " + number1 + " a perfect number? " + perfectNumber.isPerfectNumber(number1));

        int number2 = 28;
        System.out.println("Is " + number2 + " a perfect number? " + perfectNumber.isPerfectNumber(number2));

        int number3 = 12;
        System.out.println("Is " + number3 + " a perfect number? " + perfectNumber.isPerfectNumber(number3));
    }
}

Expected Output

$ javac *.java -d build
$ java -cp build ExerciseRunner
Is 6 a perfect number? true
Is 28 a perfect number? true
Is 12 a perfect number? false
$