Question: A user that inputs 1 and 3 into the following code will result in what output? int col; int row; Scanner input = new Scanner(System.in);
A user that inputs 1 and 3 into the following code will result in what output?
int col;
int row;
Scanner input = new Scanner(System.in);
String[][] board = {{" - ", " - ", " - "},
{" - ", " - ", " - "},
{" - ", " - ", " - "}};
System.out.println("\t" + Arrays.toString(board[0]));
System.out.println("\t" + Arrays.toString(board[1]));
System.out.println("\t" + Arrays.toString(board[2]) + " ");
System.out.print("X - Select row (0 - 2) & select column (0 - 2) ");
System.out.print("separated by a space: ");
row = input.nextInt();
col = input.nextInt();
board[row][col] = " X ";
System.out.println("\t" + Arrays.toString(board[0]));
System.out.println("\t" + Arrays.toString(board[1]));
System.out.println("\t" + Arrays.toString(board[2]) + " ");
- a.)
- ['-', '-', 'X']
- ['-, '-', '-']
- ['-', '-', '-']
- b.)
- ['-', '-', '-']
- ['-, '-', '-']
- ['X', '-', '-']
- c.)
- An ArrayIndexOutOfBoundsException error since the index is out of range.
- d.)
- ['-', '-', '-']
- ['-, '-', '-']
- ['-', 'X', '-']
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
