首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

一编程题?怎么触发ArithmeticException错误和IllegalArgumentException 错误

2012-12-16 
一编程题?如何触发ArithmeticException异常和IllegalArgumentException 异常/***argument()方法用于求三个

一编程题?如何触发ArithmeticException异常和IllegalArgumentException 异常
/**
*argument()方法用于求三个数的平均数,他有三个整形形式的参数,且此三个形式的参数取值范围均为【0,100】。常若形式参数的值小于0或大于100,
*常若形式参数的值小于0或大于100,程序就会抛出异常。请完成此average()方法。
*/



public class Test3{
static int average(int a,int b,int c)throws RuntimeException{
//a<0,b<0,c<0,则抛出ArithmeticException异常


//a>100,b>100,c>100,则抛出IllegalArgumentException 异常
return (a+b+c)/3;
}
public static void main(String[] args){
try{
average(-1,2,3);
}catch(RuntimeException e){
System.out.println(e);
}
}

}(发帖)
[最优解释]
这样可以吗?


public class Test3
{
static int average(int a,int b,int c)throws RuntimeException
{
//a<0,b<0,c<0,则抛出ArithmeticException异常
if(a<0 
[其他解释]
 b<0 

热点排行