下面的代码有一个编译器错误:


  speedMsg might not been initialized


我该如何解决?

String speedMsg;

// Determine the grade
if (speed >= 150)
  speedMsg = "STOP! STOP! Please let me OUT!";
else if (speed <= 150)
  speedMsg = "Whew I'll just walk from here Thanks.";

最佳答案

改成:

// Determine the grade
if (speed >= 150)
    speedMsg = "STOP! STOP! Please let me OUT!";
else
    speedMsg = "Whew I'll just walk from here Thanks.";


这应该足以让编译器确定变量将被初始化。

09-26 22:46