What is the difference between "out.println" and "out.print"???
Thanks for your help!
Difference between "out.println" and "out.print"?Difference between "out.println" and "out.print"??
Page 1 of 1
4 Replies - 90622 Views - Last Post: 07 December 2008 - 09:05 PM
#1
Difference between "out.println" and "out.print"?
Posted 07 December 2008 - 08:50 PM
Replies To: Difference between "out.println" and "out.print"?
#2
Re: Difference between "out.println" and "out.print"?
Posted 07 December 2008 - 08:52 PM
sly, on 7 Dec, 2008 - 07:50 PM, said:
What is the difference between "out.println" and "out.print"???
Thanks for your help!
Thanks for your help!
println adds a line feed at the end of the arguments
for(int i = 0; i < 5; i++) System.out.print(" " + i);
generates
0 1 2 3 4
for(int i = 0; i < 5; i++) System.out.println(" " + i);
generates
0
1
2
3
4
#3
Re: Difference between "out.println" and "out.print"?
Posted 07 December 2008 - 08:53 PM
Println - adds a new line to the end of the line. Puts the cursor on a new line
Print - prints out the line and the cursor is placed directly after it
Cheers
Print - prints out the line and the cursor is placed directly after it
Cheers
#4
Re: Difference between "out.println" and "out.print"?
Posted 07 December 2008 - 09:01 PM
ah ok thanks!
#5
Re: Difference between "out.println" and "out.print"?
Posted 07 December 2008 - 09:05 PM
This might be a good point to note the differences between next() and nextLine(). It's the same thing when you're using those for input.
Take this code for example:
If you were to input "Bob Johnson" as your name, only "Bob" would be held in the name variable. If you were to use
That would take in the whole name "Bob Johnson".
Just something to keep in mind.
Take this code for example:
Scanner input = new Scanner(System.in); System.out.println("What is your name?"); String name = input.next(); System.out.println(name);
If you were to input "Bob Johnson" as your name, only "Bob" would be held in the name variable. If you were to use
String name = input.nextLine();
That would take in the whole name "Bob Johnson".
Just something to keep in mind.
Page 1 of 1