Sha256: 3b81c893bb19ac52602023e7a9174f987a8333c52b52f167ca87f411cd2193c2
Contents?: true
Size: 843 Bytes
Versions: 284
Compression:
Stored size: 843 Bytes
Contents
import java.util.stream.IntStream; final class NaturalNumber { private final int naturalNumber; NaturalNumber(int naturalNumber) { if (naturalNumber <= 0) throw new IllegalArgumentException("You must supply a natural number (positive integer)"); 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
284 entries across 284 versions & 1 rubygems