【发布时间】:2017-10-13 14:53:45
【问题描述】:
在这段代码中,我试图在一个确定的位置拆分一个字符串,但它不起作用,我不知道该放什么,因为我知道我正在尝试将它的格式设置为“xy " 没有空格,逗号,任何东西。
import java.util.*;
public class xy {
public static void main(String[] args) {
System.out.println("Enter a number with the format 'xy'. x is the row number and y the column number.");
Scanner scanner = new Scanner(System.in);
String[] xy = scanner.nextLine().split(charAt(1)); // not sure what to put here so I tried charAt but it doesn't work
String x = xy [0];
String y = xy [1];
}
}
【问题讨论】:
-
String.substring()获取子字符串,或String.charAt()获取单个字符。请注意,它们都不返回数组,而只返回一个字符串/字符。 -
你能再补充一点吗?你期待什么样的输入?每次都会是相同类型的输入吗?用户输入的 'xy' 前后是否会有特定字符?
-
请解释"doesn't work"。