【异常概念应用】输入两个数,求商;要求编写一个类,捕获下面的异常:如果除数为0,则会抛出异常,在catch块捕获处理时输出有关的异常信息,无论是否捕捉到异常,都输出一句话:“你总能见到我”。程序类名以自己姓名拼音加题目序号命名。
package lj424;
import java.util.Scanner;
import java.lang.ArithmeticException;
public class LJ16_01 {
public static void main(String[] args) {
try {
float shang;
Scanner sc = new Scanner(System.in);
System.out.println("请输入两个数");
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println();
System.out.println(a/b);
}
catch (Exception e){
System.out.println("发生异常"+e.getLocalizedMessage());
}finally {
System.out.println("你总能见到我");
}
}
}