Console Output

To generate console output use the following method:

System.out.println("Hello World !");

The output would be:

"Hello World!"

Components of System.out.println:

  • System is a final class in java.lang package.
  • out is a static member field of System class and is of type PrintStream.
  • println is a method of PrintStream class. println prints the argument passed to the standard console and a newline.

To format your console output you can use the printf method. This example prints a float number with a width of five, and a decimal length of two:

System.out.printf("'%5.2f'%n", 5.1473);

The output would be:

' 5.15'


results matching ""

    No results matching ""