2011-12-14 60 views
1

我是编程新手,现在从Java开始。我正在阅读Robert Sedgewick和Kevin Wayne的在线版“Java编程入门”,并使用DrJava编辑器。理解问题 - System.out.println

没有给我留下想知道某一特定的运动:

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

为了使您的进一步学习更容易,下面是如何找到类似问题的答案:1)在谷歌中输入“java 6 api system”。在“class System”中导航到带有api的第一个链接。 2)找到`out`字段(在顶部),点击它的类型“PrintStream”。 3)查找`println(String x)`方法。阅读它的描述。 – bezmax 2011-12-14 14:59:51

+0

我会利用这一点,谢谢。 – Kadir 2011-12-14 15:01:50

回答

4

新生产线后打印,而不是传递给println文本之前。