int[][] shuzu=new int[n-1][n-1];这句错了。
例当 n=5 时
你的数组为 [4][4]
注意的数组是从0开始算的,从[0][0]到[3][3]
看看你的for 就知道了。

解决方案 »

  1.   

    可以揭帖了,呵呵。
    ******************************************
    import javax.swing.*;public class Matrix
    {
            public static void main(String[] args){        String input=JOptionPane.showInputDialog("What's the n?");
            int n=Integer.parseInt(input);
            int[][] shuzu=new int[n][n];  ///////定义这里出错了。
            for(int s=0;s<n;s++)
            {
                    for(int t=0;t<n;t++)
                    {                  shuzu[s][t]=1;                }
            }        for(int s=0;s<n;s++)
            shuzu[s][s]=1;        for(int s=0;s<n;s++)
            {
                    for(int t=0;t<n;t++)
                    {
                            System.out.print(" ");
                            System.out.print(shuzu[s][t]);
                    }
                    System.out.println();
            }        }
    }