The fifth exception handling operations on the machine

1. Write a class ExceptionTest, using the try-catch-finally statement structure implemented in the main method:
² in the try block, divided by the number two write operations, the division requires two operands runtime user input;
² in the catch block, the other exception is generated by the capture of 0, and outputs the abnormality information;
² in the finally block, the output of a statement.

package LHB.inherit; 
import java.util.*;
public class ExceptionTest
{

 public static void main(String[] args)
 {     
     try  
     {   
         Scanner in=new Scanner(System.in); 
         int x,y,z;
         System.out.print("请输入两个数:");
         x=in.nextInt(); 
         y=in.nextInt();   
         z=x/y; 
         System.out.print("结果是:");
         System.out.println(z); 
         }     
     catch(ArithmeticException e)     
     {     
         e.printStackTrace();   
     }  
     finally 
     {   
         System.out.println(6666); 
     } 
     }

}

 

Guess you like

Origin www.cnblogs.com/rfcd/p/10979836.html