黑马程序员技术交流社区
标题:
关于数组越界的问题,请教一下大家,谢谢
[打印本页]
作者:
大西洋
时间:
2015-4-25 19:29
标题:
关于数组越界的问题,请教一下大家,谢谢
本帖最后由 大西洋 于 2015-4-26 22:41 编辑
程序运行后会在下面这段代码的第四行报错:
错误提示:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 数组越界了
public int compare(InetAddress i1,InetAddress i2){
String[] str1 = i1.toString().split(".");
String[] str2 = i2.toString().split(".");
int num = new Integer(str1[1]).compareTo(new Integer(str2[0]));
if(num==0){
num = new Integer(str1[1]).compareTo(new Integer(str2[1]));
if(num==0){
num = new Integer(str1[2]).compareTo(new Integer(str2[2]));
if(num==0){
num = new Integer(str1[3]).compareTo(new Integer(str2[3]));
}
}
}
复制代码
请问这是什么原因??谢谢
作者:
星之钥匙
时间:
2015-4-25 20:13
能把完整的代码给出吗?
作者:
an_lucas
时间:
2015-4-25 20:41
传入的数据都不知道。。。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2