Java:处理使用子串到矩阵时的ArrayIndexOutOfBoundsException

时间:2018-04-16 00:45:44

标签: java string matrix substring

因此,我的代码应该允许您在字符串“893273872328 ...”中插入81位数字,并按照键入的顺序将它们分类为矩阵。 我的代码:

Scanner scan = new Scanner(System.in);
    String rawIn = new String(scan.nextLine());
    int[][] matIn = new int[8][8];
    for(int row = 0; row <=8; row++){
        for(int col = 0; col <=8; col++){
            matIn[row][col] = Integer.parseInt(rawIn.substring(((row+1)*(col+1)-1),(row+1)*(col+1)));
        }
    }

但是,当我运行这个并输入81位数字时,就会给我这个:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8

关于为什么这样做的任何解释都是我的算法存在缺陷?

0 个答案:

没有答案