[英]How to take multiple lines of input
If I copy and paste into a program It only takes the first line for instance I copy a few blocks from Microsoft Excel and Paste it pastes the codes like this:如果我复制并粘贴到程序中它只需要第一行,例如我从 Microsoft Excel 复制几个块并粘贴它粘贴这样的代码:
72LYY-785B9-0WQD9
88CXK-4E8BB-TA2GD
JLEIZ-0KYKP-PY2E4
LV5TL-A6CLB-P59GX
My program only takes 72LYY-785B9-0WQD9
, but I want the scanner to take all until it is empty.我的程序只需要
72LYY-785B9-0WQD9
,但我希望扫描仪全部取出,直到它为空。
I am using我在用
String userData = takeInput.nextLine();
I put it into a String and then turn it into an array of chars.我把它变成一个字符串,然后把它变成一个字符数组。
Any help?有什么帮助吗?
Did you try any other approach?你有没有尝试过其他方法?
Scanner stdin = new Scanner(new BufferedInputStream(System.in));
while (stdin.hasNext()) {
System.out.println(stdin.nextLine());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.