| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 897 人关注过本帖
标题:我这个程序有什么错误,请大虾指出!
只看楼主 加入收藏
xiayuadmin
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2004-11-12
收藏
 问题点数:0 回复次数:2 
我这个程序有什么错误,请大虾指出!
class testTry
{
public static void main(String args[])
{
Proc(0)
Proc(100)
Proc(1)
}
static viod Proc(int num)
{
try
   {
    System.out.println("*** 异常处理测试 ***");
    System.out.println("num = "+num);
    int sum =100/num;
    int array[]{0,1,2};
    array[num]=sum;
    }
catch(ArithmaticException e)
    {
    System.out.println("被零除:"+e);
catch(Array IndexOfBoundsExeption e)
     {
     System.out.println("数组越界:"+e);
     }
finally
{
System.out.println("End! \ n");
}
}
}
搜索更多相关主题的帖子: num println System 
2004-12-29 09:23
piyopiyo81
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2004-12-24
收藏
得分:0 
我也才学J2SE不久 我翻书把这个修改好了 已经Run过了 可以用

最好用eclipse来写java因为可以给你些提示而且eclipse是免费的

http://gzcnc.

-------------------------------------------------------------------------

class testTry

{

public static void main(String[] args)

{

Proc(0);

Proc(100);

Proc(1);

}

static void Proc(int num)

{

try

   {

    System.out.println("*** 异常处理测试 ***");

    System.out.println("num = "+num);

    int sum =100/num;

    int array[]={0,1,2};

    array[num]=sum;

    }catch(ArithmeticException e){

    System.out.println("被零除:"+e.getMessage());

    }catch(IndexOutOfBoundsException e){

     System.out.println("数组越界:"+e.getMessage());

}

finally

{

System.out.println("End! \n");

}

}

}

----------------------------------------------------------------------------

*** 异常处理测试 ***

num = 0

被零除:/ by zero

End!



*** 异常处理测试 ***

num = 100

数组越界:100

End!



*** 异常处理测试 ***

num = 1

End!

2004-12-29 19:50
yangjungcc
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2004-12-27
收藏
得分:0 
你的程序那么写在意思上没有什么错误,但是你的语句有一大堆的错误,例如缺分号等等。还有异常类的名字也写错了(ArithmeticException而不是ArithmaticException )。。还有后面直接用e而不用e.getMessage()实际上一点问题也没有。。不过处理异常最好用标准示误流就是System.err,因为System.out可能会重新定向。。
class testTry
{
public static void main(String args[])
{
Proc(0);
Proc(100);
Proc(1);
}
static void Proc(int num)
{
try
   {
System.out.println("*** 异常处理测试 ***");
System.out.println("num = "+num);
int sum =100/num;
int array[] = {0,1,2};
array[num]=sum;
}
catch(ArithmeticException e)
{
System.err.println("被零除:"+e);
}
catch(ArrayIndexOutOfBoundsException e)
  {
  System.err.println("数组越界:"+e);
  }
finally
{
System.out.println("End! \n");
}
}
}

[此贴子已经被作者于2004-12-30 03:38:52编辑过]


2004-12-29 21:02
快速回复:我这个程序有什么错误,请大虾指出!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017378 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved