Answer to Question #17298 in Java | JSP | JSF for Tamara

Question #17298
write method hasMidpoint that accept three integers as parameter ,and returns true if one of the numbers is the midpoint of the other two and returns false otherwise !
for example : the call hasMidpoint (3,7,5) return true because 5 is the midpoint of the other two
(3 and 7) .
1
Expert's answer
2012-10-26T10:06:25-0400
public static boolean hasMidpoing(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;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS