Why is variable initialisation redundant?
<p>I've solved a 3*N + 1 problem (100) on UVa Online Judge but here's one thing that I don't understand, but it has something to do with Java, I guess, not with the algorithm itself. So here's the code:</p>

<pre><code>private static int maxCycleLength(int lo, int hi) {
        maxLength = 0;
        int n = 0;
        int length = 0;

    for (int i = lo; i &lt;= hi; i++) {
        // It's the first time we're computing the cycle length for n
        if (lengths[i] == 0) {
            n = i;
            length = 1;
            while (n != 1) {
                if ((n % 2) == 0) {
                    n = n &gt;&gt; 1;
                    length++;
                }
                else {
                    n = 3 * n + 1;
                    n = n &gt;&gt; 1;
                    length += 2;
                }
            }
            lengths[i] = length;
        }
        // Otherwise we just look it up
        else
            length = lengths[i];

        // Check if the current cycle length is the maximum
        if (length &gt; maxLength)
            maxLength = length;
    }
    return maxLength;
</code></pre>

<p><strong>What I don't understand:</strong> My IDE (IDEA) tells me that in this piece of code the initialisation of variables <code>n</code> and <code>length</code>is redundant, however, <code>maxLength</code> must be initialised and if I don't do it, it does not compile.</p>

<p>Why so? How is <code>maxLength</code> different here from <code>n</code> and <code>length</code>?</p>