在 Java 中运行以下代码会给我一个“ArrayIndexOutOfBoundsException:215737344”
但是 SOP 语句会打印“215737344” 如果应该完成循环,为什么还要继续?
public static final int DICE_SIDE_LENGTH = 16;
static int width = 9792;
static int height = 7344;
public static void main(String args[]) throws FileNotFoundException{
byte[] imageArray = new byte[width * height * 3];
int image_at=0;
System.out.println((height/DICE_SIDE_LENGTH) * DICE_SIDE_LENGTH * (width/DICE_SIDE_LENGTH) * 16 *3 );
for(int row = 0; row<height/DICE_SIDE_LENGTH; row++){
int[] diceArray = new int[width/DICE_SIDE_LENGTH];
for(int p=0; p<DICE_SIDE_LENGTH; p++){
for(int die: diceArray){
byte[] dice_row = new byte[16];
for(int i=0; i<dice_row.length; i++){
imageArray[i + image_at]=dice_row[i];
imageArray[i + image_at+ 1]=dice_row[i];
imageArray[i + image_at + 2]=dice_row[i];
image_at+=3;
}
}
}
}
}