【发布时间】:2013-02-06 01:47:53
【问题描述】:
所以这就是我到目前为止所拥有的,我不知道为什么程序没有按照我想要的方式响应。不断显示“avg2 可能尚未初始化”。有什么想法吗??
if (a < b && a < c) {
System.out.println("The lowest score was: " + a);
System.out.println("The average without the lowest score is: " + ((b + c) / 2));
avg2 = ((b + c) / 2);
}
if (b < a && b < c) {
System.out.println("The lowest score was: " + b);
System.out.println("The average without the lowest score is: " + ((a + c) / 2));
avg2 = ((a + c) / 2);
}
if (c < a && c < b) {
System.out.println("The lowest score was: " + c);
System.out.println("The average without the lowest score is: " + ((a + b) / 2));
avg2 = ((a + b) / 2);
}
【问题讨论】:
-
这只是一个警告,但您可以将其初始化为 0 以避免这种情况。
-
@KarthikT 它对我来说更像是一个编译错误......
avg2是一个类或实例变量,不会有任何消息,或者它是一个局部变量,它不会t 编译。
标签: java if-statement variable-declaration