Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String processCompareGuess (double secretPrice, double[] playerGuess) {
- double bestDistanceFoundYet = Double.MAX_VALUE;
- String instantWinner;
- String nearest;
- // We iterate on the array...
- for (int i = 0; i < playerGuess.length; i++) {
- // if we found the desired number, we return it.
- if (playerGuess[i] == secretPrice) {
- String instantWinner = Double.toString(playerGuess[i]);
- } else {
- // else, we consider the difference between the desired number and the current number in the array.
- double d = Math.abs(secretPrice - playerGuess[i]);
- if (d < bestDistanceFoundYet) {
- // For the moment, this value is the nearest to the desired number...
- String nearest = ("Player" + i + "is the cloest guess with" + playerGuess[i]);
- d = bestDistanceFoundYet;
- }
- }
- }
- return instantWinner;
- return nearest;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement