0 day streak
java / beginner
Snippet

Methods with Parameters and Returns

Methods can take inputs called parameters and send back a value using the return keyword.

snippet.java
java
1
2
3
4
public int addNumbers(int x, int y) {
int result = x + y;
return result;
}
Breakdown
1
public int addNumbers(int x, int y)
Defines a method that takes two integers and returns an int.
2
int result = x + y;
Performs the addition of the input parameters.
3
return result;
Sends the calculated value back to the caller.