Bear Bibeault wrote:concat is a method of the String class. It cannot be used with any other type.
ints aren't even objects -- they are primitives, and as such, have no methods at all.
I'm curious: what would you expect the concatenation of two number to be?
Kyle Harris wrote:i would expect the concatenation of two numbers to be them next to each other, as opposed to added together.
So to concatenate two numbers id need to turn them into strings.
But why doesn't my string concatenation work?
Bear Bibeault wrote:
Kyle Harris wrote:i would expect the concatenation of two numbers to be them next to each other, as opposed to added together.
That's not really any sensible mathematical operation on numbers is it? That only makes sense for strings.
Its sensible if you are unaware whether it works for strings and or integer, process of elimination.
So to concatenate two numbers id need to turn them into strings.
Right, but you will end up with a string. If you need a number back, you'll need to convert again.
This is useful, thanks.
But why doesn't my string concatenation work?
Don't know. What do you mean by "doesn't work"?
Have you come across the String#valueOf() methods?
If you don't know then why comment? It's not helpful.
You know what does not work means, your just being sarcastic.
You are supposed to be a friendly place for people learning to program.
All things are lawful, but not all things are profitable.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Four and four make forty‑four.
Consider Paul's rocket mass heater. |