The number and the letter stick together when I try to compile a variable

Asked

Viewed 29 times

0

I’m creating variables, and when I compile, the number comes out "glued" to the letter. I don’t know how to explain it well, but that’s about it.

See my code below:

int numero = 24;
System.out.println("Eu gosto muito de" + numero);

The result is:

Eu gosto muito de24

Note that the 24 is next to the "de", and I wanted them to be apart, but I don’t know how to fix it.

This also happens with numbers.

1 answer

5

Concatenation does not automatically add space between your operands. This means that you must manually place space in the string:

int numero = 24;
System.out.println("Eu gosto muito de " + numero);
//                                   ↑
//                          Note o espaço aqui

See the difference in one snippet javascript:

console.log('O número é' + 10);

console.log('O número é ' + 10);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.