can I just add two string variables directly? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

can I just add two string variables directly?

like system. out. println(s+t) where s and t are string took from user input.

23rd Jul 2016, 2:21 PM
chitranjali E
chitranjali E - avatar
4 Answers
+ 2
Yes you can. If you need a space between them you can do s + " " + t
23rd Jul 2016, 2:31 PM
James
James - avatar
+ 1
yes, you can use concatenation operator + System.out.print(s1+" "+s2);
23rd Jul 2016, 3:10 PM
Hardik Patel
Hardik Patel - avatar
0
Hello Chitranjali...when you tries to add (+) two strings it concatenate to eac other and hence it will become one whole string like say s="abc" and t="def" if you write s+t it will become "abcdef"
23rd Jul 2016, 2:56 PM
Yatin Gaikwad
0
Yes, concatenating strings is commonly used to add to strings, in the underlying calls to the String class methods that add strings or subsets of strings they use the '+' concatenation operator to add strings but overload the operator to perform specific tasks, append for example adds a string to the end of your original string.
23rd Jul 2016, 4:03 PM
Eric Gitangu
Eric Gitangu - avatar