{"record":{"id":"b933f16cc2420b15","repo":"TheAlgorithms/Java","slug":"input-must-me-positive","errorCode":null,"errorMessage":"Input must me positive.","messagePattern":"Input must me positive\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/DudeneyNumber.java","lineNumber":16,"sourceCode":"package com.thealgorithms.maths;\n\n/**\n * A number is said to be Dudeney if the sum of the digits, is the cube root of the entered number.\n * Example- Let the number be 512, its sum of digits is 5+1+2=8. The cube root of 512 is also 8.\n *          Since, the sum of the digits is equal to the cube root of the entered number;\n *          it is a Dudeney Number.\n */\npublic final class DudeneyNumber {\n    private DudeneyNumber() {\n    }\n\n    // returns True if the number is a Dudeney number and False if it is not a Dudeney number.\n    public static boolean isDudeney(final int n) {\n        if (n <= 0) {\n            throw new IllegalArgumentException(\"Input must me positive.\");\n        }\n        // Calculating Cube Root\n        final int cubeRoot = (int) Math.round(Math.pow(n, 1.0 / 3.0));\n        // If the number is not a perfect cube the method returns false.\n        if (cubeRoot * cubeRoot * cubeRoot != n) {\n            return false;\n        }\n\n        // If the cube root of the number is not equal to the sum of its digits, we return false.\n        return cubeRoot == SumOfDigits.sumOfDigits(n);\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/DudeneyNumber.java#L1-L29","documentation":"Thrown by DudeneyNumber.isDudeney when n <= 0. A Dudeney number equals the cube of the sum of its digits (e.g. 512 = (5+1+2)^3 = 8^3). The implementation computes an integer cube root and a digit sum, both of which require a positive integer; zero and negatives are outside the domain. Note the message itself contains a typo ('must me positive') but the check is correct.","triggerScenarios":"Calling isDudeney(0), isDudeney(-512), or passing an unvalidated value. The guard fires before Math.pow(n, 1.0/3.0) is evaluated.","commonSituations":"Unvalidated user input parsing to 0 or negative; a loop starting at 0; reusing a variable that was reset to a default of 0.","solutions":["Pass a positive integer (>= 1) such as isDudeney(512).","Validate at the caller boundary before invoking.","If scanning a range, start the loop at 1, not 0."],"exampleFix":"// before\nboolean d = DudeneyNumber.isDudeney(0);\n\n// after\nboolean d = DudeneyNumber.isDudeney(512);","handlingStrategy":"validation","validationCode":"if (n <= 0) {\n    throw new IllegalArgumentException(\"Dudeney input must be > 0\");\n}\nDudeneyNumber.isDudeney(n);","typeGuard":"static boolean isPositive(int n) { return n > 0; }","tryCatchPattern":null,"preventionTips":["Range-check before calling; do not rely on the typo'd message in your own UI.","Start enumeration loops at 1.","Validate user or file input at parse time."],"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"}