Reading Time: 2 minutes
Print Output Using print() Method
You can send output to the screen using print() method.
print() method uses System.out.print() method to print any message passed to it.
This method internally calls System.out.print() method to perform the task.
You can pass value of any data type to print.
For example can pass String, Char, Long, Int, Float, Double etc. data type value to print to the console.
Print Output Using println() Method
You can also print output to console using println() method.
Like print() method, println() method calls also System.out.print() method to send output to the console.
You can pass value of any data type: String, Char, Long, Int, Float, Double etc. as a parameter to the function.
What is the difference between print() and println()?
- print(): This method prints value passed as parameter, but cursor remains at the end in the same line.
- println(): This method prints value passed as parameter and moves the cursor to beginning of next line.
The “\n” escape character will spawn a newline
Use this just in case if you want to print several newlines in one print statement.
If you want to print the “$” sign in your output, than you have to use backslash (“\”) before it.