Advertisement
feagans

Untitled

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