java异常各位帮我看看

成就非凡 2011-05-14 03:43:28
import java.util.Scanner;

public class test{
public static void main(String args[]){
int a,b,c=12;
try{
Scanner input=new Scanner(System.in);
System.out.println("请输入除数");
b=input.nextInt();
a=c/b;
}
catch(ArithmeticException e){
System.out.println("除数不能为0");
}
finally {
System.out.println(a);
}
}
}
...全文
114 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
vipwalkingdog 2011-05-14
  • 打赏
  • 举报
回复

兄弟,可以结贴了。
成就非凡 2011-05-14
  • 打赏
  • 举报
回复
就是finally里的a错了,感谢大家的指导,已经可以了
Isnotsuitable 2011-05-14
  • 打赏
  • 举报
回复
你那没有吗?
Isnotsuitable 2011-05-14
  • 打赏
  • 举报
回复
myeclipse应该会有错误提示的才对
Isnotsuitable 2011-05-14
  • 打赏
  • 举报
回复
import java.util.Scanner;

public class test{
public static void main(String args[]){
int a=0,b,c=12;
try{
Scanner input=new Scanner(System.in);
System.out.println("请输入除数");
b=input.nextInt();
a=c/b;
}
catch(ArithmeticException e){
System.out.println("除数不能为0");
}
finally {
System.out.println(a);
}
}
}
napier 2011-05-14
  • 打赏
  • 举报
回复
变量a在使用以前要先初始化。
magong 2011-05-14
  • 打赏
  • 举报
回复
[Quote=引用楼主 cjcf431026 的回复:]
int a,b,c=12;
[/Quote]
局部变量a和b没有初始化,c是初始化为12的。
可以把这行代码移到main方法上面去。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧