A method that returns a value:
public class Main { static int myMethod(int x) { return 5 + x; } public static void main(String[] args) { System.out.println(myMethod(3)); } } // Outputs 8 (5 + 3) |
The “return” keyword terminates the execution of a method and can be utilized to send back a value from the method.
Hint: Utilize the void keyword to indicate that a method does not return any value.
A method that does not return any value:
public
|