Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:2

shubinabc 2011-04-11 03:45:42
public class ArrayParse {

public static void main(String[] args) {

double[][] d;
String s = "1,2;3,4,5;6,7,8;";
String[] sFirst = s.split(";");
d = new double[sFirst.length][];

for(int i=0; i<sFirst.length; i++) {

String[] sSecend = sFirst[i].split(",");
d[i] = new double[sSecend.length];

for(int j=0; i<sSecend.length; j++) {

d[i][j] = Double.parseDouble(sSecend[j]);

}
}

for(int i=0; i<d.length; i++) {
for(int j=0; j<d[i].length; j++) {
System.out.print(d[i][j]);
}
System.out.println();
}
}

}
...全文
178 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
新手上路_陈 2011-09-04
  • 打赏
  • 举报
回复
public class test
{
public static void main(String args[])
{
int q=0;
int w;
int a[][]={{2,3},{4,5}};



for( w=0;w<a.length;w++)

System.out.println(a[0][w]+"");

}

}




输出那个数组,哪里出错了,求解
shubinabc 2011-04-11
  • 打赏
  • 举报
回复
谢谢回答!十分感谢!
致知Fighting 2011-04-11
  • 打赏
  • 举报
回复
数组越界错误

ff1053228 2011-04-11
  • 打赏
  • 举报
回复
for(int j=0; i<sSecend.length; j++) {
这句写错,应该改成j<sSecend.length

62,614

社区成员

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

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