变量可能尚未初始化错误
2022-08-31 12:26:00
当我尝试编译这个:
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++ ;
}
...
}
我收到以下错误:
Rand.java:72: variable a might not have been initialized
a++ ;
^
Rand.java:74: variable b might not have been initialized
b++ ;
^
2 errors
在我看来,我在方法的顶部初始化了它们。哪里出错了?