Variable might not have been initialized error

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-03-15T16:45:28Z Indexed on 2010/03/15 16:49 UTC
Read the original article Hit count: 247

Filed under:
|
|
|

When i try to compile this:

public static Rand searchCount (int[] x) 
{
    int a ; 
    int b ; 

...

        for (int l= 0; l<x.length; l++) 
        {
            if (x[l] == 0) 
            a++ ;
            else if (x[l] == 1) 
            b++ ;
        }

...

}

I get these errors:

Rand.java:72: variable a might not have been initialized
                a++ ;
                ^
Rand.java:74: variable b might not have been initialized
                b++ ;
                ^
2 errors

it seems to me that i initialized them at the top of the method. Whats going wrong?

© Stack Overflow or respective owner

Related posts about variables

Related posts about initialization