Discuss / Java / 交作业

交作业

Topic source

康208970

#1 Created at ... [Delete] [Delete and Lock User]

public static void main(String[] args) {
try {
System.out.println(tax(2000, 0.1));
System.out.println(tax(-200, 0.1));
System.out.println(tax(2000, -0.1));
}catch(IllegalArgumentException e){
e.printStackTrace();
}
}
static double tax(int salary, double rate) {
// TODO: 如果传入的参数为负,则抛出IllegalArgumentException
if(salary<0||rate<0){
throw new IllegalArgumentException();
}
return salary * rate;
}


  • 1

Reply