Alright, so I'm trying to make a very rudimentary version of battleship in order to test out my one week's worth of programming knowledge. Basically, all the program does is have the user enter two numbers and those numbers are then used to locate a slot on a multidimensional boolean array. If the array's slot is true, it should say hit. If it is false, it should say miss. However, for some reason, no matter what I enter, I keep getting "Hit! Way to go!" Fortunately, the program is displaying an error for the "else" command. It says, "The following branch is never used." Unfortunately, I don't know why the branch is never used and I don't know how to fix it. Can I have some pointers, help, and/or advice? Thanks!
import java.util.Scanner;
class Battleship {
public static void main(String[] arguments) {
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!");}
}
}}