怎么利用快站做网站,哪些网站可以接任务做兼职,网站建设要注意哪些问题,雅虎网站提交第六次实训作业异常处理 编写一个类ExceptionTest#xff0c;在main方法中使用try-catch-finally语句结构实现#xff1a;在try语句块中#xff0c;编写两个数相除操作#xff0c;相除的两个操作数要求程序运行时用户输入#xff1b;在catch语句块中#xff0c;捕获被0除… 第六次实训作业异常处理 编写一个类ExceptionTest在main方法中使用try-catch-finally语句结构实现在try语句块中编写两个数相除操作相除的两个操作数要求程序运行时用户输入在catch语句块中捕获被0除所产生的异常并输出异常信息在finally语句块中输出一条语句 import java.util.*;
public class Zzw {public static void main(String args[]) {int s,a,b;try {anew Scanner(System.in).nextInt();bnew Scanner(System.in).nextInt();sa/b;System.out.println(s);}catch(ArithmeticException e) {System.out.println(除数不能为0);}finally {System.out.println(哈哈); } }
} 类的属性“身份证号码.id”设置值当给的的值长度为18时赋值给id当值长度不是18时抛出IllegalArgumentException异常然后捕获和处理异常编写程序实现以上功能。 import java.util.*;
public class yuan {static void pop(int a) throws IllegalArgumentException{if(a!18) {throw new IllegalArgumentException(长度不是18);}}public static void main(String args[]) {Scanner bnew Scanner(System.in);String c;int d;cb.next();dc.length();try {pop(d);System.out.println(身份证号码);System.out.println(c);}catch(IllegalArgumentException e){System.out.println(e);}}
} posted on 2019-05-16 21:49 杨蒙 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/YM4396/p/10878281.html