这可能是最简单的事情之一,但我没有看到我做错了什么。
我的输入包括一个带有数字的第一行(要读取的行数),一堆带有数据的行和最后一行只有 \n。我应该处理这个输入并在最后一行之后做一些工作。
我有这个输入:
5
test1
test2
test3
test4
test5
/*this is a \n*/
为了阅读输入,我有这个代码。
int numberRegisters;
String line;
Scanner readInput = new Scanner(System.in);
numberRegisters = readInput.nextInt();
while (!(line = readInput.nextLine()).isEmpty()) {
System.out.println(line + "<");
}
我的问题是为什么我不打印任何东西?程序读取第一行,然后什么也不做。