public static void main(String[] args) {
System.out.println(Yuan.getYuanMJ(10.0));
System.out.println(Yuan.getYuanMJ(-10.0));
}
private static class Yuan{
public static Double getYuanMJ(Double r){
if (r < 0){
throw new YuanException("圆半径不能小于零");
}
return 2 * Math.PI * r;
}
}
private static class YuanException extends RuntimeException{
public YuanException(){
super();
}
public YuanException(String message){
super(message);
}
}
创建一个类,复制进去,run一下