我已经完成了完美混洗的几乎所有的java代码。我只是在努力处理这个错误:"Exception in thread "main“java.lang.ArrayIndexOutOfBoundsException: Inde26 out bounds for length 26 at cards_shuffle.main(cards_shuffle.java:72)”这个错误指的是下面这行:
Output:洗牌甲板的上半部分:
黑桃4黑桃10钻石8黑桃王牌钻石4红心杰克红心女王黑桃4黑桃杰克红桃国王红心5红桃10红桃9黑桃2梅花6黑桃钻石3梅花7黑桃钻石3红心7钻石7钻石3红桃9红桃9梅花5钻石王牌5钻石
洗牌甲板的下半部分:
红心6红心7红心10梅花王牌红心2钻石皇后6梅花8黑桃王5黑桃皇后梅花9梅花2黑桃3黑桃9黑桃10梅花7梅花2钻石6钻石4梅花8红桃5梅花8梅花杰克
卡片洗牌:
红心之六
I have just included the 6 of Hearts once but it prints out 52 times.
Any help with this error would be greatly appreciated. 发布于 2019-12-12 18:38:27
您的i变量超出了top_half的数组界限,因为它在内部循环中递增bottom_half.length次。另外,你根本不应该增加变量i,因为你想从上到下填充卡片的力。否则,您应该对它使用单独的索引。
试一试
int i = top_half.length - 1;
int j = bottom_half.length - 1;
int index = 51;
while (index >= 0) {
card_force[index--] = top_half[i--];
card_force[index--] = bottom_half[j--];
}https://stackoverflow.com/questions/59302097
复制相似问题