Question: This method returns the coordinates in a game of Battleship. Why is the array declared with two integers instead of one? It would be very

This method returns the coordinates in a game of Battleship. Why is the array declared with two integers instead of one? It would be very helpful if someone could comment each line of code so I can get a better understanding of what is going on. Thanks. public int[] getCoordinates(String input) { int[] coordinates = new int[2]; String[] strList = input.split(" "); int row = strList[0].charAt(0) - 'a'; int col = Integer.parseInt(strList[1]); coordinates[0] = row; coordinates[1] = col; return coordinates; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!