更新时间:2023-11-10 21:15:04
你声明它们,但你没有初始化它们.初始化它们就是将它们设置为一个值:
You declared them, but you didn't initialize them. Initializing them is setting them equal to a value:
int a; // This is a declaration
a = 0; // This is an initialization
int b = 1; // This is a declaration and initialization
你得到错误是因为你没有初始化变量,但是你在 for
循环中增加了它们(例如,a++
).
You get the error because you haven't initialized the variables, but you increment them (e.g., a++
) in the for
loop.
Java 原语具有默认值,但正如一位用户在下面评论的那样
Java primitives have default values but as one user commented below
当声明为类成员时,它们的默认值为零.局部变量没有默认值
Their default value is zero when declared as class members. Local variables don't have default values