Java - Introduction Console

How to output to Console window

You can use the following method to print a message on the standard output:

System.out.println("hi"); 
System.out.print(" from book2s"); 

Demo

public class Main {
  public static void main(String[] args) {

    System.out.println("hi"); 
    System.out.print(" from book2s"); 

    /*from   ww w.j  a v  a 2s  .c o  m*/
  }
}

Result

Note

System.out.println() prints text to the console, after printing the text, it prints a new line character at the end of the text.

System.out.print() does not print a new line character.

The println() and print() methods are overloaded.

You can pass any Java data type argument to these two methods.

Demo

public class Main {
  public static void main(String[] args) {
    int num = 123; 
    //from  w  w  w  .j  a v  a 2  s . co  m
    System.out.println(num); 
      
    System.out.println("Value of num = " + num); 
      
    System.out.println(); 

    
  }
}

Result

Related Topics