Knowee
Questions
Features
Study Tools

A user that inputs 2 and 1 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]) + "\n"); 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]) + "\n");

Question

A user that inputs 2 and 1 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]) + "\n"); 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]) + "\n");

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The code is written in Java and it represents a simple game board for a game like Tic Tac Toe. The board is a 3x3 grid, initially filled with " - ".

When the user inputs 2 and 1, these values are used to update the position on the board. The first number represents the row and the second number represents the column. Both are zero-indexed, so 2 and 1 would refer to the third row and second column.

The board[row][col] = " X "; line updates the selected position on the board with " X ".

After the update, the board is printed again. So, the output after a user inputs 2 and 1 would be:

[ - ,  - ,  - ]
[ - ,  - ,  - ]
[ - ,  X ,  - ]

This shows that the position at the third row and second column has been updated to " X ".

This problem has been solved

Similar Questions

A user that inputs 2 and 1 into the following code will result in what output? board = [ ["-", "-", "-"], ["-", "-", "-"], ["-", "-", "-"] ] col = int(input("X player, select a column: ")) row = int(input("X player, select a row: ")) board[row][col] = "X" print(board[0]) print(board[1]) print(board[2])

What will be the output of the following Java program? import java.io.*; class Chararrayinput { public static void main(String[] args) { String obj = "abcdefgh"; int length = obj.length(); char c[] = new char[length]; obj.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 1, 4); int i; int j; try { while((i = input1.read()) == (j = input2.read())) { System.out.print((char)i); } } catch (IOException e) { e.printStackTrace(); } } }A) abcB) abcdC) abcdeD) none of the mentioned

What will be printed out on each line?String note = "Minsub\n22\nCS";Scanner input = new Scanner(note);System.out.println("#" + input.nextLine() + "#"); System.out.println(input.nextInt()); System.out.println("#" + input.nextLine() + "#");

elect the correct answerWhat will be the output of the following Java code?class array_output {  public static void main(String args[])   {    char array_variable [] = new char[10]; for (int i = 0; i < 3; ++i)     {      array_variable[i] = 'R';      System.out.print(array_variable[i] + "");    }  } }OptionsPQR0 1 2 3 4 51 2 3 4 5 6 7 8 9 10RRR

What is the output of the following program?  public class Test {   public static void main(String[] args) {     int[][] values = {{3, 4, 5, 1 }, {33, 6, 1, 2}};      for (int row = 0; row < values.length; row++) {       java.util.Arrays.sort(values[row]);       for (int column = 0; column < values[row].length; column++)         System.out.print(values[row][column] + " ");       System.out.println();     }   } } Group of answer choicesThe program prints two rows 3 4 5 1 followed by 33 6 1 2.The program prints on row 3 4 5 1 33 6 1 2.The program prints two rows 3 4 5 1 followed by 2 1 6 33.The program prints two rows 1 3 4 5 followed by 1 2 6 33.The program prints one row 1 3 4 5 1 2 6 33.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.