我正在尝试编写询问用户年龄然后他们输入的代码,但我希望数字在您输入后出现在问题旁边。
我的代码如下所示:
System.out.println("Enter a number: ");
num1 = userIn.nextInt();
它工作正常,但数字总是出现在下面的行上。
输出:
Enter a number:
12
我想要的是:
Enter a number: 12
有什么建议么?
我正在尝试编写询问用户年龄然后他们输入的代码,但我希望数字在您输入后出现在问题旁边。
我的代码如下所示:
System.out.println("Enter a number: ");
num1 = userIn.nextInt();
它工作正常,但数字总是出现在下面的行上。
输出:
Enter a number:
12
我想要的是:
Enter a number: 12
有什么建议么?
使用print()代替println();
System.out.println()自动添加换行符。那是什么ln意思。
System.out.print而不是println.
println 在打印输出后添加一个换行符, print 只会打印您的消息。
因为您使用which在输出后System.out.println添加了一个换行符 ( )。\n改为使用System.out.print。
使用System.out.print()而不是println. 在传递参数内部的参数Println后添加一个新行。