How to print new line in Java?

Java 8Object Oriented ProgrammingProgramming

The java.io.PrintStream.println() method prints an array of characters and then terminate the line. This method behaves as though it invokes print(char[]) and then println().

Using this method you can print the data on the console.

import java.io.*;
public class PrintStreamDemo {
   public static void main(String[] args) {
      char[] c = {'a', 'b', 'c'};
      
      // create print stream object
      PrintStream ps = new PrintStream(System.out);
      
      // print an array and change line
      ps.println(c);
      ps.print("New Line");
      
      // flush the stream
      ps.flush();
   }
}

Output

abc
New Line
raja
Published on 29-Dec-2017 05:17:26
Advertisements