I know this seems like a stupid question (so excuse me). Basically this is what I want to do:
int a = 5;
int b = 3;
System.out.print(a+b);
this will give me 8, but is there a way other than putting an empty string inbetween for it to print 5 and 3 (and not by converting the int to a string)?
Thank you so much.
The print method will simply convert its argument to a string and write out the result. Therefore, if you want to display the two numbers concatenated, you will need to do this yourself by converting them to a string (either explicitly, or using "" as you've already mentioned).
If you want to avoid building the string yourself, you'd probably need to use the printf() method:
System.out.printf("%d%d", a, b);
try
System.out.print(a+""+b)
or
System.out.print(a+" "+b)
if you want a space between them
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With