august 发表于 2007-10-6 13:30:13

java题

average()方法求三个数的平均数,
int average(int a,int b,int c) throws RuntimeException{
当a<0,b<0,c<0抛出数学异常
当a>100,b>100,c>100 抛出IllegalArgumentException异常
return(a+b+c)/3;
}
应该怎么做啊

rednaxela 发表于 2007-10-6 16:25:18

原来的题目里有要求把方法声明为抛RuntimeException么,真不可思议...

1. RuntimeException是unckecked exception所以不用写在方法声明里
2. 数学异常是啥?
3. if (a > 100 || b > 100 || c > 100) throw new IllegalArgumentException("Argument too big.");
页: [1]
查看完整版本: java题