我需要一次扫描2个字符的输入,似乎无法弄清楚。
如果我有move = scan.next().charAt(0)
,那么它会给我的是第一个字符,但我需要字符串中的前2个字符
public void getChoice(){
move = ' ';
Scanner scan = new Scanner(System.in);
System.out.println("Please enter your next move: ");
move = scan.next().charAt(0);
System.out.println(move);
}
答案 0 :(得分:0)
您可以执行以下操作将字符串保存在一个变量中:
String str = scan.next();
现在得到前2个字符。
char first = str.chatAt(0);
char second = str.chatAt(1);
现在您有了字符。
任何疑问,我在这里:)