Via `Stream`

```
boolean checkPerfectNumber(int num) {
return (num >= 6) && (num == (divisors(num).sum() + 1));
}
IntStream divisors(int num) {
return IntStream.rangeClosed(2, (int) Math.sqrt(num))
.filter(i -> num % i == 0)
.flatMap(i -> IntStream.of(i, num / i));
}
```

or in a single line, if you're into that:

```
boolean checkPerfectNumber(int num) {
return (num >= 6) && (num == IntStream.rangeClosed(2, (int) Math.sqrt(num)).filter(i -> num % i == 0).flatMap(i -> IntStream.of(i, num / i)).sum() + 1);
}
```

or a constant time alternative, since there are only a few perfect numbers that are small enough:

```
boolean checkPerfectNumber(int num) {
switch(num) {
case 6: case 28: case 496: case 8_128: case 33_550_336: return true;
default: return false;
}
}
```