Reputation: 11
I'm new to programming and started out with Java today. I'm reading the online version of 'Introduction to programming in Java' by Robert Sedgewick and Kevin Wayne and using the DrJava editor.
There is a particular exercise that left me wondering:
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.".
My result looks like this:
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(".");
}
}
Now, when I type java UseThree Alice Bob Carol
it says Hi, Carol, Bob, and Alice.
But I thought that System.out.println
prints in a new line.
Shouldn't the result be like this?
Hi, Carol, Bob and Alice
.
I hope you can shed some light on the topic for me, I want to get things right from the beginning. Thank you in advance.
Greetings from Germany,
Kadir
Upvotes: 1
Views: 1402
Reputation: 726479
New line is printed after, not before the text that you pass to println
.
Upvotes: 4