第一次发博
非法数据异常IllegalArgumentException
public static int[] twoSum(int[]nums,int target){//异常:This method must return a result of type int[]
for (int i = 0; i < nums.length; i++) {
for (int j = i+1; j < nums.length; j++) {
if(nums[i]+nums[j] == target){
System.out.println("["+i+","+j+"]");
return new int[] {i,j};
}
}
}
//throw new IllegalArgumentException("没有这样的数组");//非法参数异常
}
这里如果未加throw new IllegalArgumentException(“没有这样的数组”);会报异常未返回int[]数组。