import java.util.*;
public class Exception {
public static void main(String[] args) {
for(int n=1;n<=3;n++){
try{
System.out.println("输入第"+n+"组数");
System.out.println("请输入两个整数,空格分隔,回车结束: ");
Scanner in=new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
System.out.println("第"+n+"组两整数的商:"+a+"/"+b+"="+a/b);
}
catch(ArithmeticException e){
System.out.println("发生了除数为错误!请重新输入!");
n--;
}
catch (Exception e){
System.out.println("未按要求的典型输入,请重新输入整数!");
n--;
}
}
}
}
第二种异常语句出提示:Type mismatch: cannot convert from Exception to Throwable
请问应该怎么更改?
public class Exception {这类名和系统的catch (Exception e){重复了
把自己的类名改一下或者
catch (Exception e){
改成
catch (java.lang.Exception e){
把你的类名修改一下,和系统自带的同名了
改成
catch (java.lang.Exception e)可以。但是跟类名没关系啊,改了类名还是一样的错误!
就是类型出了问题,改了就对了,我都亲自试了。。,下面那种该法是为了帮助程序指定调用lang 包中的Exception
类
你这个类名取得太强大了,直接跟系统的重名了。