我是编程新手,今天开始使用Java。我正在阅读Robert Sedgewick和Kevin Wayne的在线版“Java编程简介”并使用DrJava编辑器。
有一项特别的练习让我感到疑惑:
Modify UseArgument.java to make a program UseThree.java that takes three names and prints out a proper sentence with the names in the reverse of the order given, so that for example, "java UseThree Alice Bob Carol" gives "Hi Carol, Bob, and Alice.".
我的结果如下:
public class UseThree {
public static void main(String[] args) {
System.out.print("Hi, ");
System.out.print(args[2]);
System.out.print(", ");
System.out.print(args[1]);
System.out.print(", and ");
System.out.print(args[0]);
System.out.println(".");
}
}
现在,当我输入java UseThree Alice Bob Carol
时,它会显示Hi, Carol, Bob, and Alice.
但我认为System.out.println
会在新行中打印出来。
结果不应该是这样吗?
Hi, Carol, Bob and Alice
.
我希望你能为我说明这个话题,我想从一开始就把事情做好。提前谢谢。
来自德国的问候,
卡迪尔
答案 0 :(得分:4)
在您传递到println
的文字之前,而不是之前打印新行。