第五次实训作业异常处理

 1 package Exception;
 2 import java.util.Scanner;
 3 public class ExceptionTest 
 4 {
 5     public static void main(String[] args) 
 6     {
 7         Scanner sc=new Scanner(System.in);
 8         try
 9         {
10             System.out.println("请输入两个数:");
11             int x=sc.nextInt();
12             int y=sc.nextInt();
13             int z=x/y;
14             System.out.println("这两个数相除结果为:"+z);
15             
16         }
17         catch(ArithmeticException e)
18         {
19             
20             e.printStackTrace();
21         }
22         finally
23         {
24             System.out.println("程序运行结束!");
25         }
26         sc.close();
27         
28     }
29 }

posted @ 2019-06-10 11:45  zone静轩  阅读(65)  评论(0编辑  收藏  举报