What is the difference between System.out.println() and System.out.print() in Java?

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 12-Jan-2018 10:29:51
Advertisements