找回密码
 注册会员
查看: 602|回复: 0

菜鸟提问 高手们帮帮忙

[复制链接]
发表于 2010-3-9 16:17:27 | 显示全部楼层 |阅读模式
<p>菜鸟提问 高手们帮帮忙</p>
<p><img src="http://img.baidu.com/img/iknow/icn_point.gif"> 悬赏分:0 -</p>
<p>解决时间:2010-3-9 16:17</p>
<p>public class Test {</p>
<p>public static void main(String[]args) {</p>
<p>Test t = new Test();</p>
<p>t.m(0);</p>
<p>void m(int i) throws ArithmeticException {</p>
<p>if(i == 0)</p>
<p>new throw ArithmeticException("被除数为0");</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>为什么我不能编译</p>
<p>而马士兵老师就能呢?</p>
<p>谢谢大家了</p>
<p>提问者: seer890304 - 二级</p>
<p>最佳答案</p>
<p>原因很简单</p>
<p>是因为你的类方法写到main方法里面了</p>
<p>public static void main(String[]args) {</p>
<p>Test t = new Test();</p>
<p>t.m(0);</p>
<p>void m(int i) throws ArithmeticException {</p>
<p>if(i == 0)</p>
<p>new throw ArithmeticException("被除数为0");</p>
<p>}</p>
<p>}</p>
<p>应该将m这个方法写在main方法外面</p>
<p>现给你改成</p>
<p>public class Test {</p>
<p>public static void main(String[]args) {</p>
<p>Test t = new Test();</p>
<p>t.m(0);</p>
<p>}</p>
<p>void m(int i) throws ArithmeticException {</p>
<p>if(i == 0)</p>
<p>new throw ArithmeticException("被除数为0");</p>
<p>}</p>
<p>}</p>
<p>0</p>
<p>回答者:</p>
<p><img src="http://img.baidu.com/img/iknow/icon_lights.gif"></p>
<p><img src="http://img.baidu.com/img/iknow/icon_huizhang.gif"></p>
<p>godcomexxx - 七级   2010-3-9 16:10</p>
<p>我来评论>></p>
<p>提问者对于答案的评价:</p>
<p>大哥 太谢谢你了</p>
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|文字版|手机版|小黑屋|襄阳城

GMT+8, 2025-8-3 10:56

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表