0

基本的には、2 つの座標の傾きを求めるプログラムを作成したいと考えています。私はこれを行いましたが、ユーザーがプログラムを終了して再度開くことなく、別の勾配を見つけるために、プログラムを再起動するかどうかをプログラムに尋ねさせたいと考えています。これは私のコードで、不要なビットをすべて差し引いたものです。

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 に答える