Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Does anyone know the answer to this question about variables?

+6 votes
On the PowerPoint for today's lesson, one of the examples went like this:

int x;


System.out.println(x + "is here");

Why aren't we using quotation marks in the beginning and ending of the println statements as we have done before?
asked Aug 29, 2016 in CSC 211 (F16) by Jordan Peklo (100 points)

1 Answer

+3 votes

The quotation marks at anywhere in the println statement indicate the beginning of a string.

For example, println("hehe") prints out the string "hehe".

If you use the quotation marks at the very beginning and at the very end as well, it would be "x + is here", and the console literally print out "x + is here".

The plus sign is not the same as the plus sign in 3 + 7. It indicates that the value of x will be added to the string "is here"

What we want the console to print out is the value of x, and "is here" right next to it, so the println(x + "is here") would print out "3 is here", instead of "x + is here".

answered Aug 29, 2016 by Minh Ta (1,045 points)