Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();
int sum = 0;
for (int i = 1; i <= n / 2; i++) {
if (n % i == 0) {
sum += i;
}
}
if (sum == n && n != 0) {
System.out.println(n + " is a Perfect Number");
} else {
System.out.println(n + " is not a Perfect Number");
}
sc.close();
}
}Output
Enter a number: 28 28 is a Perfect Number
We sum all positive divisors less than the number; if this sum equals the number, it is perfect.