class NumberException extends Exception {
    NumberException() {}    void dis(int x) {
        final int year = 2005;
        int age = year - x;
        int diver = age - 16;
        try {
            if (age < 16) {
                System.out.println("年龄是: " + age);
                throw new NumberException();
            }
            if (diver < 4) {
            System.out.println("每年支付1000元的保险费");
        } else {
            System.out.println("每年支付600元的保险费");
        }
        } catch (NumberException e) {
            System.out.println("年龄太小,无需保险!");
        }
    }
}
class InsuranmeCalculater {
    InsuranmeCalculater() {}    public static void main(String[] args) {
        NumberException obj = new NumberException();
        int x = Integer.parseInt(args[0]);
        obj.dis(x);
    }}能编译,就是执行时错了

解决方案 »

  1.   

    我估计肯定没有,改成这样将就着用吧!  public static void main(String[] args) {
        NumberException obj = new NumberException();
        String year = args.length==0?"1980":args[0]; // 如果没输入参数,就用1980年出生的好了
        int x = Integer.parseInt(year);
        obj.dis(x);
      }
      

  2.   

    Exception in thred"main" java.lang.NoclassDefFoundError:InsuranceCalculater
    出现这样的错误