Try writing this yourself before reading the solution. Create a method called add that takes int parameters and returns their sum. Call it from main and print the result.
public class AddNumbers {
public static int add(int a, int b) {
return a + b;
}
public static void main(String[] args) {
int sum = add(3, 4);
System.out.println(sum);
}
}
The method add declares int parameters, adds them, and returns the result. In main, you call add(3, 4) and store the returned value in sum. Try changing the arguments to different numbers and verify the output.