Sha256: e0b339c49a94b7c21d13bdbf62812c1789b45e299c7b47b1430a62f536bad8f5
Contents?: true
Size: 822 Bytes
Versions: 24
Compression:
Stored size: 822 Bytes
Contents
import java.util.stream.IntStream; final class NaturalNumber { private final int naturalNumber; NaturalNumber(int naturalNumber) { if (naturalNumber <= 0) throw new IllegalStateException("Natural numbers are all positive."); this.naturalNumber = naturalNumber; } Classification getClassification() { final int aliquotSum = computeAliquotSum(); if (aliquotSum == naturalNumber) { return Classification.PERFECT; } else if (aliquotSum > naturalNumber) { return Classification.ABUNDANT; } else { return Classification.DEFICIENT; } } private int computeAliquotSum() { return IntStream.range(1, naturalNumber) .filter(it -> naturalNumber % it == 0) .sum(); } }
Version data entries
24 entries across 24 versions & 1 rubygems