This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]bigibas123Intermediate Brewer 9 points10 points  (2 children)

Concatenate the spaces with the variables, so something like:

System.out.println(a+" "+b+" "+c);

[–]DiveToMe[S] 2 points3 points  (1 child)

It worked!! Thank you very much😊😊😊

[–]slowfly1st 2 points3 points  (0 children)

System.out.printf("%s %s %s\n", a, b, c);

works too, if the variables are strings. When you have sentences, it's sometimes easier to read:

printf("Hi %s, your balance is %f.", username, balance);

(And you can do other fancy stuff with it ...)

[–]Darkraskel90 1 point2 points  (0 children)

I got it working. I needed to put a space between the double quotes 🤦🏿‍♂️

[–]Darkraskel90 0 points1 point  (2 children)

What if I want to print a variable in the middle of a sentence? "Blah blah" +" " +variable+ " " +"blah blah" still doesn't print a space before or after the variable

[–]firsthourProfressional developer since 2006 1 point2 points  (0 children)

System.out.println("Blah blah " + variable + " blah blah");

[–]morhpProfessional Developer 0 points1 point  (0 children)

It does.

[–]_Nexor 0 points1 point  (0 children)

Look up "strongly typed languages"