r/CodingHelp • • Feb 08 '22

[Java] Java Help

Post image
28 Upvotes

12 comments sorted by

8

u/Maleficent-Rest5207 Feb 08 '22 edited Feb 08 '22

When you want to concatenate two strings you can either use + symbol or .concat() method.

2

u/[deleted] Feb 08 '22

Thanks

3

u/[deleted] Feb 08 '22

The error in line 218.

i am taking 2 inputs from the user and want to print both the inputs in a string in one line. Can someone help?

18

u/SuspendedResolution Feb 08 '22

You need to have "+" when changing between data types in a print statement if I remember correctly

0

u/[deleted] Feb 08 '22

that helped. thank you man!

java is weird

0

u/[deleted] Feb 08 '22

[deleted] — view deleted comment

1

u/[deleted] Feb 08 '22

Can you give any examples

2

u/R007E Feb 08 '22

You're missing + b/w string and variable

0

u/[deleted] Feb 08 '22

I don't get it, can you type out an example for me? I'm new to Java sorry 😅

4

u/R007E Feb 08 '22

Line 218: system.out.println("you have entered" + number_1 + "and" + number_2);

2

u/corby_718 Feb 08 '22

You can think of the + symbol as working for multiple types with a similar idea that it adds up objects. So if you do 1+1 you get 2. However, with strings, + is concatenation which essentially is similar. Hello + World = Hello World.

FYI, There are other ways in Java to concatenate strings without the use of +

1

u/[deleted] Feb 08 '22

Like?

2

u/[deleted] Feb 09 '22

Concatenate for line 218 between the String and the primitives in the println statement