我想在過程中編寫一段簡單的代碼來創建Connect 4遊戲。我試圖創建和顯示6 7板因爲這樣,我終於可以放下X和O的:Java錯誤:線程「main」中的異常java.lang.ArrayIndexOutOfBoundsException:6
||||||||
||||||||
||||||||
||||||||
||||||||
||||||||
我不斷收到錯誤:異常線程「main」 java.lang.ArrayIndexOutOfBoundsException:6
public static void printConnect4Board(){
final int WIDTH = 6;
final int HEIGHT = 7;
int [] [] connect4Board = new int [WIDTH][HEIGHT];
Scanner input = new Scanner(System.in);
for(int w = 0; w < connect4Board.length; w++){
for(int h = 0; h < connect4Board[w].length; h++){
System.out.println(connect4Board[w][h] + "|");
}
System.out.println();
}
}
任何幫助將不勝感激。謝謝。
應該是'connect4Board [H]在第二到最後一行[W]'。 –