Difference Between System.out.println and System.out.print in Java



The println() terminates the current line by writing the line separator string. The print() method just prints the given content.

Example

Live Demo

public class Sample {
   public static void main(String args[]) {
      System.out.println("Hello");
      System.out.println("how are you");
      System.out.print("Hello");
      System.out.print("how are you");
   }
}

Output

Hello
how are you
Hellohow are you
Updated on: 2020-02-20T08:19:37+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements