不知道为什么,把double改成int之后,就会和毕老师课中的实例那样报错。如果改成double的话,就能通过编译,并能运算,运算结果为:Infiniy。
- class Shang
- {
- public static double chu(double a,double b)
- {
- double num = a/b;
- return num;
- }
- }
- class DemoException
- {
- public static void main(String[] args)
- {
- Shang s = new Shang();
- double x;
- try
- {
- x = s.chu(5,0);
- System.out.println(x);
- }
- catch (Exception e)
- {
- System.out.println(e.getMessage());
- System.out.println(e.toString());
- }
- System.out.println("over!");
- }
- }
复制代码
|
|