所以我正在编写一些模拟三角纸牌游戏的代码。教授希望按以下格式立即输入电路板布局:
P
PP
OPP
POPP
PPPPP
PPPPPP
并且需要扔进6x6数组
但是当我使用这段代码时:
Scanner consoleInput = new Scanner(System.in);
System.out.println("INPUT INSTRUCTIONS: Please input board data via copy/paste.");
System.out.println("Any invalid character (not 'o' or 'p') will be change to 'o' automagically.");
String input = consoleInput.next();
while (consoleInput.hasNextLine()) {
String line = consoleInput.nextLine();
System.out.println(line);
}
consoleInput.close();
一切都打印正常,但第一行被跳过。在花了两个小时后,我头上的头发掉了大约 50%...
谢谢!
最佳答案
String input = consoleInput.next();
是您的第一行。
关于Java 扫描器 ".nextLine"和 ".hasNextLine"未获取第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23001816/