1

いくつかの設定を求めるスキャナーがあります。0 から 3 の間のint変数を作成します。次に、次のようにします。choice

String location;
switch(choice){
    case 0:
        System.out.println("Please type the zip codes you would like to search in a comma separated list");
        location = input.nextLine();
        break;
    case 1:
        System.out.println("Please type the street names you would like to search in a comma separated list");
        location = input.nextLine().toUpperCase();
        break;
    case 2:
        System.out.println("Please type the boroughs you would like to search in a comma separated list");
        location = input.nextLine().toUpperCase();
        break;
    default:
        location = "none";
        break;
    }
String locations[] = location.split("\\s*,\\s*");

これで問題ないように思えますが、choice が 0、1、または 2 に設定されている場合、正しい行が出力されますが、ユーザーが何かを入力しなければならない部分 (location=... のような行) はスキップされます。

これは、ユーザーに何も入力する機会を与えないためlocations、空白のリストになることを意味します。なぜこれが起こり、どうすれば修正できますか?

4

3 に答える 3

0

私はあなたと同じ問題に直面しました。試す:

case 'f' :
                System.out.println("Enter a word or phrase to be found:");
                scnr.nextLine();
                String phrase = scnr.nextLine(); //
于 2018-10-11T19:03:27.830 に答える