public boolean horizontal(Populate a, int[][][] ar, int row, int col, int dep)
    {
        ar = new int[6][6][6];
        a.pop(ar);
        for(dep=0;dep<6;dep++)
        {
            for(col=0;col<6;col++)
            {
                for(int count=0;count<5;count++)
                {    
                    int num = ar[row][col][dep];
                    int num1 = ar[row+1][col][dep];
                    if(num==num1)
                    {
                        count1++;
                    }
                    row++;
                }   
            }
        }
        if(count1==5)
            return true;
        else
            return false;
    }
这段代码应该扫描一个 3d 数组以查找 6 的水平行(如老虎机),如果扫描则返回 true,否则返回 false。它编译但是当我尝试运行它时得到一个 ArrayOutOfBoundsException:6 。
for(int count=0;count<5;count++)
即使我尝试将上面的这一行更改为下面的内容(就像只是降低循环的距离),它仍然超出范围。
 for(int count=0;count<2;count++)
任何建议或解决方案表示赞赏。谢谢你。
如果有帮助的话,这就是我调用该方法的地方。
    public class runCheck
    {
        public static void main(String[] args)
        {
            Populate ch = new Populate();
            int[][][] ar = new int[6][6][6];
            ch.pop(ar);
            ArrayList al = new ArrayList();
            scan a = new scan();
            boolean abool = a.horizontal(ch,ar,0,0,0);
            if(abool==true)
                al.add(true);
        }
    }