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

Why would you use the print function rather than the println function?

+3 votes
asked Aug 25 in CSC 211 (F17) by Zayne Blumberg (100 points)

1 Answer

+1 vote

A print statement just prints the parameters to the line the console is on and does not proceed to the next line. A println statement, on the other hand, prints the parameters and continues to the next line.

You would use a print statement if there might be more you wanted to print on the same line later (like if you had a series of print statements that should all go on the same line), or if you wanted user input to show up on the same line. For instance, after running a simple multiplier program, the console might look like (user input bolded):

Enter number 1: 6
Enter number 2: 7
6 x 7 = 42

If you wanted the user to be able to input the 6 and 7 on the same line they're requested, you would have to use print statements, rather than println for the "Enter number #:" output.

On the other hand, you could use println statements to make it look like:

Enter number 1:
6
Enter number 2:
7
6 x 7 = 42
answered Aug 25 by Vecna (100 points)
...