• Post Reply Bookmark Topic Watch Topic
  • New Topic

concatenation is not working as intended  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello again,

User inputs certain variables for the story, the problem I am having is the concatenation is not working as intended. the story part with the + parts all come back with an error. I thought I had it correct but obviously i don't.

Any help on the story part? please? thank you.



 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read ItDoesntWorkIsUseless. Then follow the guidelines - i.e. tell us what the exact error is.
 
Adrian Martinez
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the error i receive when i try to compile.



 
Marshal
Posts: 4054
241
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a read through Oracle's Strings Tutorial paying particular attention to the "Concatenating Strings" section.

See if you can see where you're going wrong.
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try sorting out the first error and recompiling. You have missed something out. If you sort out one error, many of the others will probably vanish.
I suggest you learn about formatted printing, which is neater than catenating multiple strings with +.

you should be compiling after writing 5 to 10 lines. Writing 40 lines before trying to compile something is too much. As you see, you get lots of errors and might not be able to work out where they occurred. In this case, they were all in the same place, but that is unusual.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
another tip...look closely at the code you posted. You see how a string literal is blue (i.e. anything INSIDE double quotes). Here is your line in question:



Do you see how towards the end, things get "off"? I'd suggest removing most of this line, and add pieces back in a bit at a time, recompiling and testing often - for this line alone, i'd probably recompile/test between 5-10 times as I add a little more each time.
 
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adrian Martinez wrote:



I can see at least 6 things wrong with this line of code. You need to put a + between ALL the terms.

Edit : It seems I'm a day or so too slow!
 
Ranch Hand
Posts: 99
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check where you missed the + signs. The below line of code is compiling fine.

System.out.println("There was once a person named " + name + " who lived in city " + city + ". At the age of " + age + " " + name + " went to college at " + college + ". " + name + " graduated and went to work as a " + profession + ". Then adopted an animal " + animal + " named " + pet + " . They both lived happily ever after." );

Thanks,
Aakash
 
Adrian Martinez
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you again, i couldn't figure it out .
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!