如何在输出后将我的用户输入保持在同一行? [英] How to keep my user input on the same line after an output?
本文介绍了如何在输出后将我的用户输入保持在同一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写代码,询问用户年龄,然后他们输入,但是我希望数字在输入后出现在问题旁边.
I'm trying to write code that asks for the users age and then they enter it, but I want the number to appear next to the question after you enter it.
我的代码如下:
System.out.println("Enter a number: ");
num1 = userIn.nextInt();
它可以正常工作,但是数字始终显示在下面的行中.
It works fine, but the number always appears on the line below.
输出:
Enter a number:
12
我想要的:
Enter a number: 12
有什么建议吗?
推荐答案
使用print()
代替println()
;
System.out.println()
自动添加换行符.就是ln
的意思.
System.out.println()
automatically adds a newline character. That what the ln
means.
这篇关于如何在输出后将我的用户输入保持在同一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文