Java.io.PrintStream.println() Method



Description

The java.io.PrintStream.println() method prints a long and then terminate the line. This method behaves as though it invokes print(long) and then println().

Declaration

Following is the declaration for java.io.PrintStream.println() method.

public void println(long x)

Parameters

x − The long to be printed.

Return Value

This method does not return a value.

Exception

NA

Example

The following example shows the usage of java.io.PrintStream.println() method.

package com.tutorialspoint;

import java.io.*;

public class PrintStreamDemo {
   public static void main(String[] args) {
      long c = 1512344125l;
      
      try {
         // create printstream object
         PrintStream ps = new PrintStream(System.out);

         // print a long and change line
         ps.println(c);
         ps.print("New Line");

         // flush the stream
         ps.flush();

      } catch (Exception ex) {
         ex.printStackTrace();
      }
   }
}

Let us compile and run the above program, this will produce the following result −

1512344125
New Line
java_io_printstream.htm
Advertisements