java / beginner
Snippet
Method Return Values
Methods can perform a calculation and send the result back to the place where the method was called using the 'return' keyword.
snippet.java
1
2
3
int multiply(int x, int y) {return x * y;}
Breakdown
1
int multiply(...)
The 'int' before the method name specifies that the method returns an integer.
2
return x * y;
The 'return' keyword exits the method and provides the result.