数组下标越界 求高手指点

Bateagle 2012-04-25 09:26:11
import java.math.*;
public class BigPI {
public static BigDecimal compute(int n){
BigDecimal t = new BigDecimal(1);

for(int i = 1; i <= n; i++){
t = t.multiply(
new BigDecimal(4 * i * i * 1.0 / (4 * i * i - 1)));
}
t = t.multiply(new BigDecimal("" + 2));
return t;
}

public static void main(String[] args) {
System.out.println(compute(Integer.parseInt(args[0])));

eclipse:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at exercise1.BigPI.main(BigPI.java:17)

不知道哪里有错误,求指点
...全文
190 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
五哥 2012-04-26
  • 打赏
  • 举报
回复
public static void main(String[] args) {
if(args.length == 0){
System.out.println("请输入参数,eg: java BigPI XX ");
System.exit(0) ;
}
System.out.println(compute(Integer.parseInt(args[0])));
qq274188468 2012-04-26
  • 打赏
  • 举报
回复
arg[0] 很明显 你不给arg添加元素 他是长度为空的
普凡 2012-04-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

你有配置传入main方法的参数吗?没有的话肯定会报错
[/Quote]

++
Bateagle 2012-04-25
  • 打赏
  • 举报
回复
这个参数该怎么传呢 
安特矮油 2012-04-25
  • 打赏
  • 举报
回复
你有配置传入main方法的参数吗?没有的话肯定会报错
古市轩 2012-04-25
  • 打赏
  • 举报
回复
楼主的main方法中使用了args[0],也就要在运行时传入参数的,运行前先配置参数!
wang4016 2012-04-25
  • 打赏
  • 举报
回复
main方法中args[0]参数没有输入吧
w304341736 2012-04-25
  • 打赏
  • 举报
回复
args[0]参数没有输入吧
huxinxinxin 2012-04-25
  • 打赏
  • 举报
回复
args[0]这个参数没有看到你获得,怎么可能不错报
hu0905074231 2012-04-25
  • 打赏
  • 举报
回复
java BigPI 参数
szx0704 2012-04-25
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

这个参数该怎么传呢
[/Quote]
用dos运行。。。java BigPI “字符串”
这样就给main传入“字符串”了

62,614

社区成员

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

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