Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote