正在加载图片...
65创建自己的异常类示例 public class Example6 3 i public static void main(String[] args)t Scanner reader new Scanner(System. in)i double num =0 double deno s 0: tryi System. out. printin(“请输入被除数:”) num reader, nextDoubleo System, out. println(“请输入除数:”) deno reader. nextDouble; if(deno ==0.0) throw new my ExceptionoF System. out println(“商是:”+(num/deno) } catchi( my Exception e) System. out. printIn(“出现异常:”+ etoString catch(Exception er System. out. println(“出现异常:”+ e tostring)6.5 创建自己的异常类—示例 public class Example6_3 { public static void main(String[] args){ Scanner reader = new Scanner(System.in); double num = 0; double deno = 0; try{ System.out.println(“请输入被除数:”); num = reader.nextDouble(); System.out.println(“请输入除数:”); deno = reader.nextDouble(); if(deno = = 0.0) throw new myException(); System.out.println(“商是:”+(num/deno)); } catch(myException e){ System.out.println(“出现异常:”+e.toString()); } catch(Exception e){ System.out.println(“出现异常:”+e.toString()); }}}
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有