{"record":{"id":"295e8946a97077fb","repo":"TheAlgorithms/Java","slug":"iterations-must-be-at-least-1","errorCode":null,"errorMessage":"Iterations must be at least 1","messagePattern":"Iterations must be at least 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/others/PageRank.java","lineNumber":191,"sourceCode":"    }\n\n    /**\n     * Validates input parameters for PageRank calculation\n     *\n     * @param totalNodes    the total number of nodes\n     * @param dampingFactor the damping factor\n     * @param iterations    number of iterations\n     * @throws IllegalArgumentException if parameters are invalid\n     */\n    private void validateInputParameters(int totalNodes, double dampingFactor, int iterations) {\n        if (totalNodes < 1 || totalNodes > MAX_NODES) {\n            throw new IllegalArgumentException(\"Total nodes must be between 1 and \" + MAX_NODES);\n        }\n        if (dampingFactor < 0 || dampingFactor > 1) {\n            throw new IllegalArgumentException(\"Damping factor must be between 0 and 1\");\n        }\n        if (iterations < 1) {\n            throw new IllegalArgumentException(\"Iterations must be at least 1\");\n        }\n    }\n\n    /**\n     * Initializes PageRank values for all nodes\n     *\n     * @param totalNodes      the total number of nodes\n     * @param initialPageRank the initial PageRank value\n     * @param verbose         whether to print output\n     */\n    private void initializePageRanks(int totalNodes, double initialPageRank, boolean verbose) {\n        for (int i = 1; i <= totalNodes; i++) {\n            pageRankValues[i] = initialPageRank;\n        }\n\n        if (verbose) {\n            System.out.println(\"\\nInitial PageRank Values, 0th Step\");\n            printPageRanks(totalNodes);","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/others/PageRank.java#L173-L209","documentation":"Thrown by PageRank.validateInputParameters when iterations < 1. PageRank approximates ranks by repeated relaxation; zero or negative iterations would skip the computation entirely and leave ranks uninitialized, so at least one iteration is required.","triggerScenarios":"Triggering a calculation with iterations = 0 or negative; an iterations count derived from a precision/epsilon setting that rounds down to 0.","commonSituations":"A 'precision' setting mapped to 0 iterations; default value unset resolving to 0; logic that decrements iterations until 0.","solutions":["Pass iterations >= 1 (a few dozen is typical for convergence).","Default iterations to a positive value when unset (e.g. 20-100).","Clamp the computed iteration count to a minimum of 1.","Validate at the boundary where the parameter is parsed."],"exampleFix":"// before\npageRank.calc(totalNodes, damping, iterations); // iterations may be 0\n\n// after\nint iters = Math.max(1, iterations);\npageRank.calc(totalNodes, damping, iters);","handlingStrategy":"validation","validationCode":"int safeIterations = Math.max(1, iterations);\npageRank.calc(totalNodes, dampingFactor, safeIterations);","typeGuard":"public static boolean isPositiveIterations(int iters) {\n    return iters >= 1;\n}","tryCatchPattern":"try {\n    pageRank.calc(total, damping, iters);\n} catch (IllegalArgumentException e) {\n    pageRank.calc(total, damping, Math.max(1, iters));\n}","preventionTips":["Always pass iterations >= 1; 20-100 is typical.","Clamp precision-derived iteration counts to a minimum of 1.","Default iterations to a positive value when unset."],"tags":["validation","pagerank","iteration","input-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}