ArrayIndexOutOfBoundsException
在 Java中获取字符串输入时,我得到了Java。请帮我。这是我的代码:我编辑了要拆分的代码:它说“线程中的异常”main“java.lang.ArrayIndexOutOfBoundsException:1 at solution2.Solution.main(Solution.java:27)”
import java.util.Scanner;
公共类解决方案{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String str = scan.next();
String strarr[] = str.split(",");
String temp = strarr[0];
String temparr[] = temp.split(".");
String temp1 = strarr[1];
String temparr1[] = temp.split(".");
int x1 = Integer.parseInt(temparr[0]);
int x2 = Integer.parseInt(temparr[1]);
int y1 = Integer.parseInt(temparr1[0]);
int y2 = Integer.parseInt(temparr1[1]);
System.out.println(distance(x2,x1,y2,y1));
}
public static int distance(int x1,int y1,int x2,int y2){
int xlen=x2-x1;
int ylen=y2-y1;
return (xlen+ylen)*10-(ylen*5);
}
}