Advertisement
feagans

Untitled

Apr 20th, 2014
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public static String processCompareGuess (double secretPrice, double[] playerGuess) {
  2.  
  3. double bestDistanceFoundYet = Double.MAX_VALUE;
  4. // We iterate on the array...
  5. for (int i = 0; i < playerGuess.length; i++) {
  6. // if we found the desired number, we return it.
  7. if (playerGuess[i] == secretPrice) {
  8. return playerGuess[i];
  9. } else {
  10. // else, we consider the difference between the desired number and the current number in the array.
  11. double d = Math.abs(secretPrice - playerGuess[i]);
  12. if (d < bestDistanceFoundYet) {
  13. // For the moment, this value is the nearest to the desired number...
  14. String nearest = ("Player" + i + "is the cloest guess with" + playerGuess[i]);
  15. d = bestDistanceFoundYet;
  16. }
  17. }
  18.  
  19. }
  20. return nearest;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement