Java 越界例外:6
我正试图创建一个程序,将发挥游戏连接四。当尝试插入计数器时,它编译没有问题,但当我尝试在程序中输入某些内容时,它会显示以下消息: java.lang.ArrayIndexOutOfBounds异常:6 在突出线条的同时 所涉及的全部方法是:Java 越界例外:6,java,loops,for-loop,Java,Loops,For Loop,我正试图创建一个程序,将发挥游戏连接四。当尝试插入计数器时,它编译没有问题,但当我尝试在程序中输入某些内容时,它会显示以下消息: java.lang.ArrayIndexOutOfBounds异常:6 在突出线条的同时 所涉及的全部方法是: public static void playGame() { Scanner input = new Scanner(System.in); String[][] board = new String[6][7]; for (int
public static void playGame() {
Scanner input = new Scanner(System.in);
String[][] board = new String[6][7];
for (int i = 0; i < board.length; i++)
for (int j = 0; j < board[i].length; j++)
board[row][col] = " ";
int column = 0;
for (int i = 0; i <= 6; i++) {
displayBoard();
String turn = "R" ;
System.out.print("Red player enter number 0 - 6: ");
column = input.nextInt();
System.out.print("|" + " " + board[row][col]);
board[row][col] = "R";
displayBoard();
}
}
publicstaticvoidplaygame(){
扫描仪输入=新扫描仪(System.in);
字符串[][]板=新字符串[6][7];
对于(int i=0;i 对于(inti=0;i你需要根据电路板的长度而不是一些幻数来确定i
//use the i & j's to set your board
for (int i = 0; i < board.length; i++)
for (int j = 0; j < board[i].length; j++)
board[i][j] = " ";
for (int i = 0; i < board.length; i++) {
displayBoard();
String turn = "R" ;
System.out.print("Red player enter number 0 - 6: ");
column = input.nextInt();
System.out.print("|" + " " + board[i][column]);
board[i][column] = "R";
displayBoard();
}
//使用i&j设置电路板
对于(int i=0;i
你为什么不使用i
和j
而不是行
和col
?你的代码没有意义。请提供一个。你说我
//use the i & j's to set your board
for (int i = 0; i < board.length; i++)
for (int j = 0; j < board[i].length; j++)
board[i][j] = " ";
for (int i = 0; i < board.length; i++) {
displayBoard();
String turn = "R" ;
System.out.print("Red player enter number 0 - 6: ");
column = input.nextInt();
System.out.print("|" + " " + board[i][column]);
board[i][column] = "R";
displayBoard();
}