急,求会JAVA的人帮助啊‘!

[复制链接]
查看11 | 回复2 | 2008-10-16 17:16:39 | 显示全部楼层 |阅读模式
1.参考下面的程序,试修改程序,捕获相关异常,使得程序能正常运行。
public class ex51
{
public static void main(String args[])
{
System.out.println("字符串索引越界异常");
String str=args[0];
System.out.println(“第四个字符为 ”+str.charAt(3));
int aa=Integer.parseInt(args[0]);
System.out.println(“平方为 ”+aa*aa);
}
}
这个怎么写做哦?

回复

使用道具 举报

千问 | 2008-10-16 17:16:39 | 显示全部楼层
public class io {public static void main(String args[]){ try{ System.out.println("字符串索引越界异常");
String str=args[0];
System.out.println("第四个字符为 " + str.charAt(3));
int aa=Integer.parseInt(str);
System.out.println("平方为 " + aa*aa);
}catch(ArrayIndexOutOfBoundsException e){ System.er...
回复

使用道具 举报

千问 | 2008-10-16 17:16:39 | 显示全部楼层
public class ex51 { public static void main(String args[]) {try {System.out.println("字符串索引越界异常"); String str=args[0]; System.out.println("第四个字符为 "+str.charAt(...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行