【发布时间】:2017-11-05 10:51:18
【问题描述】:
有人知道我如何拆分输入,例如:
P K K R
K P K V
到不同的字符串? 现在我的代码就是这样,但是在第一行之后它会抛出错误,因为车道开关是 \n (enter) 而不是空格
Scanner sc = new Scanner(System.in);
String[] input = new String[7];
String c1, c2, c3, c4, q1, q2, q3, q4;
input = sc.nextLine().split(" ");
c1= input[0];
c2= input[1];
c3= input[2];
c4= input[3];
q1= input[4];
q2= input[5];
q3= input[6];
q4= input[7];
【问题讨论】:
-
在第一行之后仍然抛出错误。 ://
-
您想用 \n 编写这 8 个字符,然后代码必须读取并拆分?为什么不是所有 8 个都在同一行?^^
-
学校工作。 Bot 会抛出这样的输入:/