实训作业6
1. 编写一个类ExceptionTest,在main方法中使用try-catch-finally语句结构实现: ² 在try语句块中,编写两个数相除操作,相除的两个操作数要求程序运行时用户输入; ² 在catch语句块中,捕获被0除所产生的异常,并输出异常信息; ² 在finally语句块中,输出一条语句。 package trouble; import java.util.*; public class ExceptionTest { public static void main(String[] args) { int a,b; int c=0; Scanner a1 = new Scanner(System.in); System.out.println("请输入除数"); a = a1.nextInt(); System.out.println("请输入被除数"); b = a1.nextInt(); try{ c=a/b; }catch(ArithmeticException e){ e.printStackTrace(); System.out.println("异常"); }finally{ System.out.println("商:"+c); System.out.print("program over"); } } } 1. 编写一个应用程序