-1

从下面的代码中,我发现车辆制造商和型号的输入打印在单独的行上,我该如何避免这种情况。我还附上了输出的副本

System.out.print("Enter Hire Length (in days):");
int hLength = Integer.parseInt(input.nextLine());
System.out.println("Enter Vehicle Make and Model:");
makeMod = input.nextLine();     
System.out.print("Enter Vehicle registration No:");
regNum = input.nextLine();  

输出

Enter Hire Length (in days):9
Enter Vehicle Make and Model: <<< this is where the Issue is Mazda 3 should be after here
Mazda 3                       <<< Not here
Enter Vehicle registration No:YJZ 561
4

4 回答 4

3

您应该将 println 更改为在第 3 行打印

System.out.print("Enter Vehicle Make and Model:");
于 2013-09-09T04:40:32.390 回答
1

System.out.print()当您希望光标停留在输出打印到的当前行时,您需要使用。System.out.println()在刚刚打印的输出末尾附加一个换行符,这就是为什么当您输入值时光标现在将位于下一行的原因。

于 2013-09-09T04:45:00.123 回答
0
 System.out.println("Enter Vehicle Make and Model:");

因此,println()总是在新行中打印。使用print()与您在其他两个中已使用的相同。

于 2013-09-09T04:45:01.837 回答
0

删除波纹管声明

System.out.println("Enter Vehicle Make and Model:");

& 像这样 System.out.print("输入车辆品牌和型号:");

println 和 print 有区别

于 2013-09-09T04:45:24.853 回答