<h2>
Answer:</h2>
//Method sum header declaration.
//The return type of the method be of type int,
//since the sum of integer numbers is an integer.
//It has the variables a and b as parameter
public static int sum(int a, int b){
//Since the method will sum numbers between a and b,
//it implies that a and b are not inclusive.
//Therefore, increment variable a by 1 before starting the loop
//and make sure the loop does not get to b
//by using the condition a < b rather than a <=b
a++;
//Declare and initialize to zero(0) a variable sum to hold the sum of the numbers
int sum = 0;
//Begin the while loop.
//At each cycle of the loop, add the value of variable a to sum
//and increment a by 1
while(a < b) {
sum = sum + a;
a++;
}
//at the end of the loop, return sum
return sum;
} // End of method sum
<h2>
Explanation:</h2>
The above code has been written in Java. It also contains comments explaining every section of the code. Please go through the comments for better understanding.
The overall code without comments is given as follows;
public static int sum(int a, int b) {
a++;
int sum = 0;
while (a < b) {
sum = sum + a;
a++;
}
return sum;
}