Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

new line character

 
Ken Anderson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no problem using the println() function when needed, but cannot get the newline character \n to work. Each attempt to use it, the compiler says "invalid character". This happens no matter where I insert it, front, middle or end of a sentence. Any suggestions?
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it included as a part of a string ? can you show your code ?
 
Ken Anderson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if ( count >= 56 )
\nSystem.out.print( args.[i] ) ;
above gives invalid character.

if ( count >= 56 )
System.out.println( args.[i] ) ;
above works fine except newline comes after i is printed
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The line you have that doesn't work isn't printing the newline.
You need to include it in the string that is output...

or even better (since the newline character is system dependant)...

or if you're looking for a third answer:

Dave.
[This message has been edited by David O'Meara (edited May 15, 2001).]
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See what a difference makes posting a little code
 
Ken Anderson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a bunch Val and David. That works great. I see what you mean about a little bit of code. It does kind of show where the error is right away.
 
Ken Anderson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Val and David. Posting code does make a difference doesn't it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic