{"record":{"id":"234a46b2d3d27e85","repo":"TheAlgorithms/Java","slug":"input-must-be-a-positive-integer","errorCode":null,"errorMessage":"Input must be a positive integer.","messagePattern":"Input must be a positive integer\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/DisariumNumber.java","lineNumber":24,"sourceCode":" * Example: 135 = 1^1 + 3^2 + 5^3 = 1 + 9 + 125 = 135\n *\n * @see <a href=\"https://en.wikipedia.org/wiki/Disarium_number\">Disarium Number</a>\n */\npublic final class DisariumNumber {\n\n    private DisariumNumber() {\n    }\n\n    /**\n     * Checks if a number is a Disarium number.\n     *\n     * @param number the number to check (must be positive)\n     * @return true if number is Disarium, false otherwise\n     * @throws IllegalArgumentException if number is not positive\n     */\n    public static boolean isDisarium(int number) {\n        if (number <= 0) {\n            throw new IllegalArgumentException(\"Input must be a positive integer.\");\n        }\n        int digits = String.valueOf(number).length();\n        int temp = number;\n        int sum = 0;\n        while (temp > 0) {\n            int lastDigit = temp % 10;\n            sum += (int) Math.pow(lastDigit, digits);\n            digits--;\n            temp /= 10;\n        }\n        return sum == number;\n    }\n}\n","sourceCodeStart":6,"sourceCodeEnd":38,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/DisariumNumber.java#L6-L38","documentation":"Thrown by DisariumNumber.isDisarium when number <= 0. A Disarium number is one where the sum of each digit raised to the power of its position equals the number (e.g. 89 = 8^1 + 9^2). The position-based computation requires at least one digit, and zero/negative numbers are outside the defined domain, so the library rejects non-positive input before computing digit count.","triggerScenarios":"Calling isDisarium(0), isDisarium(-175), or passing an unvalidated parsed integer. The guard fires before String.valueOf(number).length() is used to seed the position counter.","commonSituations":"User input that is empty or a minus sign and parses to 0 or negative; a loop boundary starting at 0; default int field value of 0 passed inadvertently.","solutions":["Pass a positive integer (>= 1) such as isDisarium(89).","Validate at the caller: if (number <= 0) reject with a user message.","Parse-and-check before calling, especially for data from files or forms."],"exampleFix":"// before\nboolean d = DisariumNumber.isDisarium(0);\n\n// after\nboolean d = DisariumNumber.isDisarium(89);","handlingStrategy":"validation","validationCode":"if (number <= 0) {\n    throw new IllegalArgumentException(\"Disarium input must be > 0\");\n}\nDisariumNumber.isDisarium(number);","typeGuard":"static boolean isPositive(int n) { return n > 0; }","tryCatchPattern":null,"preventionTips":["Reject 0 and negatives at the input boundary.","Start scan ranges at 1.","Validate parsed integers before classification calls."],"tags":["validation","number-theory","precondition","domain-error"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}