Syntax error How to print new line in Java?

How to print new line in Java?



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
Updated on: 2019-07-30T22:30:20+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements