Help me find a mistake, pliz. I am trying to write console tic-tac-toe, but one of the cycles does not think to end, although it seems like all the conditions for this are fulfilled. The cycle itself:
do { Scanner coord = new Scanner(System.in); System.out.println(player1Name + ", введите номер ячейки по горизонтали (от 1 до 3):"); x = coord.nextInt() - 1; System.out.println(player1Name + ", введите номер ячейки по вертикали (от 1 до 3):"); y = coord.nextInt() - 1; if (field[x][y] == '_'){ field[x][y] = 'X'; } else { System.out.println("Это поле уже занято, попробуйте снова."); } for (x = 0; x < SIZE; x++) { for (y = 0; y < SIZE; y++) { System.out.print(field[x][y] + " "); } System.out.println(); } System.out.println(); } while (field[x][y] == 'X'); The problem is somewhere here while (field[x][y] == 'X'); as I understand it, but what the problem is, it does not reach me. The 3x3 field, if the player enters the coordinates x = 1, y = 2, then the field will be displayed
_ Х _ _ _ _ _ _ _ Those. as it should, but the test at the end of the cycle does not pass and again begins to twist again.
Fully error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3 at Main.main(Main.java:80) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
ArrayIndexOutOfBoundsExceptionoccurs - default localeat Main.main(Main.java:80)i.e. just wherewhile (field[x][y] == 'X');- tryhard