Write a method named hasMidpoint that accepts three integers as parameters and r
ID: 660792 • Letter: W
Question
Write a method named hasMidpoint that accepts three integers as parameters and returns true if one of the integers is the midpoint between the other two integers; that is, if one integer is exactly halfway between them. Your method should return falseif no such midpoint relationship exists.
The integers could be passed in any order; the midpoint could be the 1st, 2nd, or 3rd. You must check all cases.
Calls such as the following should return true:
Calls such as the following should return false:
Method problem: For this problem, you are supposed to write a Java method as described. You should notwrite a complete Java class; just write the method(s) described in the problem statement.
Explanation / Answer
public static boolean hasMidpoint(int one, int two, int three) {
if ((two + three)/2 == one){
return true;
}
else if ((one + three)/2 == two){
return true;
}
else if ((one + two)/2 == three){
return true;
}
return false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.