0 day streak
java / beginner
Snippet

Defining a Simple Method

Methods are blocks of code that perform a specific task and can be reused. They can take parameters (input) and return a value (output).

snippet.java
java
1
2
3
public static int addNumbers(int a, int b) {
return a + b;
}
Breakdown
1
public static int
Defines the access level, static nature, and the return type (int) of the method.
2
return a + b;
The 'return' keyword sends the result back to the caller.