简体   繁体   English

多次使用来自扫描仪的用户输入?

[英]Using user input from a scanner multiple times?

I am trying to use a user-entered number from the scanner in my code in multiple places.我正在尝试在我的代码中的多个位置使用扫描仪中用户输入的数字。 Below the line should be the same user-entered number as the first.该行下方应该是与第一个相同的用户输入的数字。 Is this possible?这可能吗?

Scanner inputHere = new Scanner(system.in);
System.out.println("Please select me");
String inputHereOne = inputHere.nextLine();
System.out.println("----------------------------------");

Yes, it's possible.是的,这是可能的。 Use the value stored in inputHereOne .使用存储在inputHereOne中的值。 No need to call inputHere.nextLine() until you actually need the next line of input.在您真正需要下一行输入之前,无需调用inputHere.nextLine() Like so:像这样:

System.out.println(inputHereOne);
System.out.println(inputHereOne);

This will print inputHereOne , twice.这将打印inputHereOne两次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM