我试图将一个字符串拆分为一个字符串数组,但是当它拆分字符串时,只有第一部分在拆分之前位于 [0] 插槽的数组中,但在 [1] 或更高版本中没有任何内容。这在尝试输出 spliced[1] 时也会返回 java 异常错误
import java.util.Scanner;
public class splittingString
{
static String s;
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter the length and units with a space between them");
s = input.next();
String[] spliced = s.split("\\s+");
System.out.println("You have entered " + spliced[0] + " in the units of" + spliced[1]);
}
}