System.out.print() vs System.out.println()

https://www.codecademy.com/courses/learn-java/lessons/learn-java-manipulating-variables/exercises/introduction?action=resume_content_item

I noticed when I typed in System.out.print(), Codeacademy said it was incorrect, yet, when I put in System.out.println(), it was correct.

I know that the difference between the two is that print() will print the output all in one line, like this:
hello world

While println() will print the output by seperating the lines, like this:
hello
world

Are there any differences I need to know between those two specifically in terms of variables as well as in a more general scope of Java programming

Edit: I noticed this has been happening throughout the “manipulating variables” unit. Which one and when do you use the two?

Which one to use would be strictly a matter of preference or whichever is best suited to your desired outcome out in the real world. In the context of a Codecademy lesson, you have to use the one specified. If neither is specified, you may still only have one or the other accepted by the SCT that checks your code. Frequently in all Codecademy lessons there is only one specific solution accepted by the SCT. After submitting the acceptable answer, you are free to play around with the code, and see what else will also work. Hope this helps!

Did you use ; after () for example System.out.println(“Hello world”); for text and System.out.println(VARIABLE); to print variables

Hello estorliao, welcome to the community :+1:

You need to use ; after every line of code unless it:
ends in a bracket, which means it closes something.
is a comment, which is done with // and /* */
is written in the terminal, where some commands are not java.

Hope this helps you! :smile: :smile:

Hi there,
I would like to confirm the difference between using Print() vs Println(). From my understanding it means that unlike System.out.println(), this type of print statement outputs everything on the same line.

However, when I used both forms in an exercise both resulted in the statements being on the same line, why is that?
Please see image reference. Screenshot 2021-01-02 at 20.44.45|690x196

I’d invite you to read the java documentation on the matter: PrintStream (Java Platform SE 8 )

Note how there are very specific different behaviors depending on the type of the arguments that print() and println() are provided (by type I’m referring to ints, doubles, strings, Objects, etc.)