Join the social network of Tech Nerds, increase skill rank, get work, manage projects...

• # How to Allow 2 Users One at a Time to Place Their Ships on a Board

• 0
• 0
• 0
• 0
• 0
• 0
• 0
• 372

Please check the code below and provide a solution for this:

package Gui;
import java.util.Scanner;

public class Board {

public static void main(String[] args) {
// TODO Auto-generated method stub

// Implement scanner5
Scanner input = new Scanner(System.in);

String player1 = input.nextLine();

String player2 = input.nextLine();

// create loop for accepting matrix input
// first accept row size
System.out.println("Please enter the number of rows in your matrix. Must be 35 or less.");
int row = input.nextInt();

while (row > 35 || row < 1) {
System.out.println("Sorry. Your number is not the correct size. "
+ "Please enter the number of rows in your matrix. Must be between 35 and 1.");
row = input.nextInt();
}

// next accept column size
System.out.println("Please enter the number of columns in your matrix. Must be 35 or less.");
int column = input.nextInt();

while (column > 35 || column < 1) {
System.out.println("Sorry. Your number is not the correct size. "
+ "Please enter the number of columns in your matrix. Must be between 35 and 1.");
column = input.nextInt();
}

// declare array with row and columns the user gave
int[][] userArray = new int[row][column];

for(int i=0;i< row ; i++){
for(int j=0; j< column; j++) {
System.out.print("");
int val = 0;
if(val>10 || val< -10) {
System.out.println("Invalid value.");
continue;
}
userArray[i][j] = val;
}
}
printMatrix(userArray, row, column);
}

public static void printMatrix(int[][] array, int row, int column) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
System.out.print(array[i][j] + " ");
}
System.out.println();}
}
}

OR
OR
Register

OR
Fill out the form below and instructions to reset your password will be emailed to you:

• Hire
• Post Projects

### Post Projects

• All at 0 Cost ....
• Post Tech Job
• Select Best Bidder
• Track the Project
• Approve Work and Pay safely
• Browse Nerds
• Work
• Find Projects Find Projects
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
• Manage
• Company Company

### Manage Company

• All at 0 Cost ....
• Manage Company and Employee Profiles
• Company wide Employee Productivity Reports
• Knowledge Sharing and Collaboration Tools
• Get Sales Lead and Bid for Tech Projects
• Send Invoices and Receive Payment Safely
• Learn
• Nerd Digest Nerd Digest
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General
• Tech Q & A Tech Q & A
• UI Design and UX
• Software Engineering
View more...
View less...
• Marketing
• General