这样写,算不算抛出了IllegalArgumentException异常?
class p9
{
public static void main(String[] args)
{
char []arr={'a','b','c','d'};
char a='a';
int p=get(arr,a);
System.out.println(p);
System.out.println(arr.toString());
}
public static int get(char arr[],char a)
{
try
{
if(arr==null);
throw new IllegalArgumentException();
}
catch (Exception e)
{
}
for(int i=0;i<arr.length ;i++ )
{
if(a==arr[i])
return i;
}
return -1;
}
}
|
|