AP Computer Science Exam Question:
Write a Java method named calculateSum that takes two integer parameters, num1 and num2, and returns their sum.
Signature:
public static int calculateSum(int num1, int num2) {
// code goes here
}
Example Input:
calculateSum(5, 7)
Example Output:
12
Explanation:
public static int calculateSum(int num1, int num2) {
int sum = num1 + num2; // adding the two numbers
return sum; // returning the sum
}
calculateSum with return type int and two parameters num1 and num2.sum.num1 and num2 to the sum variable using the + operator.sum using the return keyword.calculateSum is called with the arguments (5, 7), it will calculate the sum as 12 and return it as the output.