杭电ACM1002用java写的,麻烦高手看一下哪里错了,在线
大体是用二维数组写的,报错
Exception in thread "main"
java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: -1
at java.lang.String.substring(Unknown Source)
at ACM1002.main(ACM1002.java:16)
麻烦看一下,在线等...
import java.util.Scanner;
public class ACM1003{
public static void main(String[]args){
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
String s[][] = new String[i][2];
int j[][] = new int[1][2];
for(int m=0;m<i;m++){
String s2 = scan.next();
int e = s2.indexOf(' ');
s[m][0] = s2.substring(0,e);
s[m][1] = s2.substring(e);
j[m][0] = Integer.parseInt(s[m][0]);
j[m][1] = Integer.parseInt(s[m][1]);
}
for(int n=1;n<=i;n++){
System.out.println("Case " + n +":");
System.out.println(j[n][0] + " + " + j[n][1] + " = " + (j[n][0] + j[n][1]));
System.out.println();
}
}
}
------解决方案--------------------
这个应该是下标越界的报错吧。