次のコードがあり、到達不能ステートメント エラーが発生しています。問題の行の後に、それが原因であるというコメントがあります。
public static void selectPlayer ()
{
// Loops through Player class' static array. If an index is storing a player object then print the player name out with a number for selection.
for(int i=0; 1<101; i++)
{
if (Player.playerArray[i] != null)
{
System.out.println(i + ". " + Player.playerArray[i - 1].playerName);
}
System.out.print("\nPlease enter the number that corresponds to the player you wish to use; "); // This line is where it failed to compile a la unreachable statement.
Scanner scanner = new Scanner(System.in);
// Take players selection and minus 1 so that it matches the Array index the player should come from.
int menuPlayerSelection = scanner.nextInt() - 1;
// Offer to play a new game with selected player, view player's stats, or exit.
System.out.print("You have selected " + Player.playerArray[menuPlayerSelection].playerName + ".\n1) Play\n2) View Score\n3) Exit?\nWhat do you want to do?: ");
int areYouSure = scanner.nextInt();
// Check player's selection and run the corresponding method/menu
switch (areYouSure)
{
case 1: MainClass.playGame(menuPlayerSelection); break;
case 2: MainClass.viewPlayerScore(menuPlayerSelection); break;
case 3: MainClass.firstMenu(); break;
default: System.out.println("Invalid selection, please try again.\n");
MainClass.firstMenu();
}
}
私の質問は、どうすれば修正できますか? 到達不能ステートメントエラーが通常発生する理由はわかりますが、私の場合はなぜ発生しているのかわかりません。