return

Keyword "return" ends the method execution, returning a value.

int twice(int value) {
  return 2 * value;
}

If a method does not return a value, that means if the declared return type is "void", only use the word "return" without a value. Or just let the method finish automatically, by executing its last line of code.

void writeNumber(int value) {
  System.out.println(value);
}  // method ends here

void writeNumberUnlessNegative(int value) {
  if (value < 0) {
    return;  // exit the method now
  }
  System.out.println(value);
}  // method ends here

viliam@bur.sk