What is the 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
Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest


Advertisements