Mer*_*mas 2 java arrays string split java.util.scanner
我试图将一个字符串拆分成一个字符串数组,但是当它拆分字符串时,只有第一部分,在拆分之前,在[0]插槽中的数组中,但是[1]或更晚的内容中没有任何内容.这也会在尝试输出拼接时返回java异常错误[1]
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]);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
574 次 |
最近记录: |