Advertisement
feagans

Untitled

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