int [] arr=new int[31]; 数组被初始化为31个0
然后
c.arr(arr,4)
由于index<0不成立,所以直接返回arr[4]
然后呢?没有打印语句,控制台当然不会有显示啦

解决方案 »

  1.   

    class FushuIndexException extends Exception
    { FushuIndexException(String a)
    {
    super(a);
    }}class method
    {
    public int arr(int[] arr, int index) throws FushuIndexException
    {
    if (index < 0)
    {
    throw new FushuIndexException("我学会啦~");
    }
    return arr[index];
    }}class Cn
    {
    public static void main(String[] args) throws FushuIndexException
    {
    int[] arr = new int[31];
    method c = new method();
    System.out.println(c.arr(arr, 4));   //打印语句 }
    }