BufferedReader 输入
我有一个如下的代码段,它使用 BufferedReader 从命令 shell 读取输入:
String choice = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("\nEnter choice: ");
choice = br.readLine();
在本例中,假设“3”是我的输入,控制台打印如下:
输入选择:
3
我想知道如何使控制台打印如下:
输入选择:3
感谢任何帮助!
I have a code segment as below that uses BufferedReader to read inputs from command shell:
String choice = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("\nEnter choice: ");
choice = br.readLine();
In this case, assuming '3' is my input, the console prints as follows:
Enter choice:
3
I would like to know how can I make the console prints such that it appears as follows:
Enter choice: 3
Appreciate any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 System.out.println("\nEnter choice "); 更改
为
System.out.print("\nEnter choice: ");
(
println 在输入字符串末尾添加行终止符)
Change
System.out.println("\nEnter choice ");
to
System.out.print("\nEnter choice: ");
(
println
adds a line terminator at the end of the input string)