いくつかの設定を求めるスキャナーがあります。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
、空白のリストになることを意味します。なぜこれが起こり、どうすれば修正できますか?