package com.lk.classTest;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
* @author:Melirn
* @e-mail:2227287556@qq.com
* @date:2021.5.6
*/
public class three {
public static void main(String[] args) {
try {
divide();
}catch (InputMismatchException e){
System.err.println("出现错误:被除数和除数必须是整数");
}catch (ArithmeticException e){
System.err.println("出现错误:除数不能为零");
}catch (Exception e){
System.err.println("其他未知异常");
}finally {
System.out.println("感谢使用本程序");
}
}
public static void divide()throws Exception{
Scanner input = new Scanner(System.in);
System.out.println("请输入被除数");
int num1 = input.nextInt();
System.out.println("请输入除数");
int num2 = input.nextInt();
System.out.println(String.format("%d/%d=%d",num1,num2,num1/num2));
}
}
throws的使用练习
最新推荐文章于 2022-02-18 17:36:44 发布