0

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

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"));
    }
}

我遇到的问题是我收到错误“找不到符号”的参考行

while(cont.equalsIgnoreCase("Y"));

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

4

1 回答 1

0

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

    String cont = "Y";
    do {
        ...
        cont = console.readLine(" Find another slope? Y/N  ");
    } while (cont.equalsIgnoreCase("Y"));
于 2015-08-05T11:37:05.240 回答