• Post Reply Bookmark Topic Watch Topic
  • New Topic

print vs println  RSS feed

 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone explain the difference between print vs println? I know that println prints to a new line, but on the code below, when I use System.out.println(i);, the loop does not print 2,4 and 6 ( prints from 8 to 100) where System.out.print(i); does this from 2. Can anybody tell me what is exactly going on here?

Thank you.

 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should be no difference except of new lines being added.
Maybe the whole output exceeds limits of your console?
 
Jude Niroshan
Ranch Hand
Posts: 132
5
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both ways it works fine for me.....(starting from 2)

Paweł Baczyński --- might be correct with exceeding the console output limit.
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried again and again. Same thing happens all the time. (I do not change anything else)
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you run this? What OS?
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it was console limit then it shouldn't prit the last numbers, am I wrong?
 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hans Baba wrote:if it was console limit then it shouldn't prit the last numbers, am I wrong?

Yes, you are. In case of exceeding the limit all consoles I know remove the oldest lines.
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using BlueJ IDE on MAC
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right
 
Tim Cooke
Marshal
Posts: 4041
239
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to eliminate any console buffer issues, turn your upper loop boundary down from 100 to something smaller, say 20.

That will allow you to observe the difference in behaviour between print() and println().
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah I used a smaller number and what you guys said is true. (Just found out line-limit on my consol is 47 )

Well, this is what being is a beginner. You will hear lots of silly questions like this from me
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hans Baba wrote:Well, this is what being is a beginner. You will hear lots of silly questions like this from me

There are no silly questions. Silly answers, perhaps...

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hans Baba wrote:yeah I used a smaller number and what you guys said is true. (Just found out line-limit on my consol is 47 )

Well, this is what being is a beginner. You will hear lots of silly questions like this from me

I would say this question has come up at least once a year since I joined the Ranch. It's not silly at all...it's really just one of experience. Things you never think of until they happen to you. The trick is to not ask this question yourself a SECOND time.
;-)
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just FYI, if you're using CMD on Windows you can increase the buffer by right-clicking on the console window's title bar, selecting Properties from the right-click menu and then on the Layout tab increase the value of the Height property for Screen Buffer Size.
For instance, by default my CMD window is set to a buffer width of 180 and a buffer height of 9999, while the window size is set to width 180 and height 80.
 
Jeff Boynton
Greenhorn
Posts: 18
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method "print" leaves the insertion point after the last character of
the value of an expression, while the method "println" positions the insertion point at
the beginning of the next line
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!