hasMidpoint
Category: Programming
Author: Stuart Reges
Book Chapter: 4.1
Problem: hasMidpoint
Write a method called hasMidpoint that takes three integers as parameters and that returns true if one of the numbers is the midpoint of the other two and that returns false otherwise. A number is considered the midpoint of two numbers if it appears halfway between them. For example, 12 is the midpoint of 10 and 14. The numbers might be in any order, so any one of the three might be the midpoint of the other two. The table below shows sample calls and the value that should be returned. Method Value Method Value Call Returned Call Returned --------------------------------- --------------------------------- hasMidpoint(10, 12, 14) true hasMidpoint(14, 10, 12) true hasMidpoint(12, 10, 14) true hasMidpoint(2, 10, 6) true hasMidpoint(8, 8, 8) true hasMidpoint(25, 10, -5) true hasMidpoint(2, 3, 4) true hasMidpoint(2, 3, 5) false hasMidpoint(3, 1, 3) false hasMidpoint(2, 4, 5) false hasMidpoint(21, 9, 58) false hasMidpoint(2, 8, 16) false