Error: Cannot Find Symbol / No Spelling Mistakes?

Error: Cannot Find Symbol / No Spelling Mistakes?

基本上,我想创建一个程序来计算两个坐标的斜率。我已经这样做了,但我希望程序询问是否要重新启动——例如,找到不同的坡度,而无需用户退出并重新打开程序。 这是我的代码,减去了所有不必要的位:

import java.io.Console;

public class slopeFinder{
    public static void main(String[] args) {
    Console console = System.console();
    do{
    /* code to find slope here.
It asks for the X1, Y1, X2 and Y2 values using the readLine method on console
and then it parses the Strings and then does the math, obviously. Then it 
prints out the slope. */
    }
    String cont = console.readLine(" Find another slope? Y/N  ");
    }
    while (cont.equalsIgnoreCase("Y"));
    }
}

我遇到的问题是我在引用

行时收到错误 "cannot find symbol"
while(cont.equalsIgnoreCase("Y"));

我不明白我做错了什么?一切都拼写正确..

cont 在循环内声明,因此它不在循环条件的范围内。你应该在循环之前声明它。

    String cont = "Y";
    do {
        ...
        cont = console.readLine(" Find another slope? Y/N  ");
    } while (cont.equalsIgnoreCase("Y"));