• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding + in string and \n .

 
WeiJie Lim
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The above code will result in :
Welcome to the voting machine error code decoder.

If your voting machine generates an error code,
you can use this program to determine the exact
cause of the error.

However, I decide to remove all the + . I didn't think it is neccessary.. or am I wrong. Nevertheless, I tried and the result is really different. Why is this so ?
I tried :


Resulted in :
Welcome to the voting machine error code decoder.
If your voting machine generates an error code,
you can use this program to determine
the exact
cause of the error.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to be honest I am suprised it compiled, when i cut and paste it into eclipse


it didn't compile. So any results you get are completely random, as strings are not meant to go over line ends (wrap).
That is what all the + are for
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WeiJie Lim wrote:However, I decide to remove all the + . I didn't think it is neccessary.. or am I wrong.

You can do that but then you would need to write the whole string on one line, otherwise you will get compiler errors, as Wendy tried. Java does not allow you to open a string literal on one line and close it on another line.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic