Difference between "out.println" and "out.print"?

Difference between "out.println" and "out.print"??

Page 1 of 1

4 Replies - 32885 Views - Last Post: 07 December 2008 - 09:05 PM Rate Topic: -----

#1 sly  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 134
  • Joined: 05-December 08

Difference between "out.println" and "out.print"?

Post icon  Posted 07 December 2008 - 08:50 PM

What is the difference between "out.println" and "out.print"???

Thanks for your help!
Is This A Good Question/Topic? 0
  • +

Replies To: Difference between "out.println" and "out.print"?

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Difference between "out.println" and "out.print"?

Posted 07 December 2008 - 08:52 PM

View Postsly, on 7 Dec, 2008 - 07:50 PM, said:

What is the difference between "out.println" and "out.print"???

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
Was This Post Helpful? 1

#3 markhazlett9  Icon User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 60
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

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
Was This Post Helpful? 1
  • +
  • -

#4 sly  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 134
  • Joined: 05-December 08

Re: Difference between "out.println" and "out.print"?

Posted 07 December 2008 - 09:01 PM

ah ok thanks!
Was This Post Helpful? 0
  • +
  • -

#5 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 89
  • View blog
  • Posts: 797
  • Joined: 25-February 08

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:
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.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1