next up previous
Next: Objects and classes in Up: Unit 02 Previous: Method calls

Difference between the methods print() and println()

public class MyMessage2 {
  public static void main(String[] args) {
    System.out.print("JA");
    System.out.print("VA");
    System.out.println();
  }
}

The println("...") method prints the string "..." and moves the cursor to a new line. The print("...") method instead prints just the string "...", but does not move the cursor to a new line. Hence, subsequent printing instructions will print on the same line. The println() method can also be used without parameters, to position the cursor on the next line.


next up previous
Next: Objects and classes in Up: Unit 02 Previous: Method calls