申し訳ありませんので、私は1週間分のプログラミング知識をテストするために非常に初歩的な戦艦を作ろうとしています。基本的には、すべてのプログラムはユーザーが2つの数字を入力させ、それらの数字を使用して多次元ブール配列のスロットを探します。配列のスロットがtrueの場合、ヒットとなります。それが偽であれば、それはミスを意味するはずです。しかし何らかの理由で、私が何を入力しても、私は「ヒット!幸いにも、プログラムは "else"コマンドのエラーを表示しています。それは、次のブランチは決して使用されないと言います。残念ながら、ブランチが使用されなかった理由はわかりません。そのブランチを修正する方法がわかりません。私はいくつかの指針、助け、助言をすることができますか?ありがとう!戦艦のJava版。条件文が発行されています。 "ブランチは一度も使用されていません"
import java.util.Scanner;
class Battleship {
public static void main(String[]arguements) {
System.out.println(" Welcome to Battleship Solo Edition!");
System.out.println(" There are seven boats scattered across this 10 by 10 grid.");
System.out.println(" When you get a \'Hit!\', mark it on your accompanying paper.");
System.out.println(" Once you have completely shot down all seven boats (18 Hits), you win!");
System.out.println(" But play carefully! You only have 50 missiles.");
System.out.println();
boolean[][] field = new boolean [10][10];
//Ship one
field[8][2] = true;
field[8][3] = true;
field[8][4] = true;
field[8][5] = true;
field[8][6] = true;
//Ship two
field[1][9] = true;
field[2][9] = true;
//Ship three
field[2][4] = true;
//Ship four
field[2][2] = true;
field[3][2] = true;
field[4][2] = true;
//Ship five
field[4][8] = true;
field[5][8] = true;
field[6][8] = true;
field[7][8] = true;
//Ship six
field[6][3] = true;
field[6][4] = true;
//Ship seven
field[6][6] = true;
for (int missileattempts=0; missileattempts<=50; missileattempts++){
System.out.println("What is the X-Coordinate of your guess?");
Scanner scan = new Scanner(System.in);
int AnswerX = scan.nextInt();
System.out.println("What is the Y-Coordinate of your guess?");
Scanner scan2 = new Scanner(System.in);
int AnswerY = scan.nextInt();
if (field[AnswerX][AnswerY]=true){
System.out.println("Hit! Way to go!");}
else {System.out.println("Miss! Try again!");}
}
}}
私はまだJavaに慣れていないので(すべてありがとう! –