Guest User

Untitled

a guest
Nov 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class GuessingGame
  5. {
  6.  
  7. /**
  8. * @param args
  9. */
  10. public static void main(String[] args)
  11. {
  12. Random r = new Random();
  13. Scanner inp = new Scanner(System.in);
  14.  
  15. int guess = 0, rounds = 0, tmp = 0, numPlayers = 0;
  16. int answer = r.nextInt(10);
  17.  
  18. System.out.print("Enter the number of players: ");
  19. numPlayers = inp.nextInt() + 3;
  20.  
  21. String[] players = new String[(numPlayers - 3)];
  22.  
  23. for (int x = 0; x < (numPlayers - 3); x++)
  24. {
  25. System.out.print("\nEnter player " + (x + 1) + "'s name: ");
  26. players[x] = inp.nextLine();
  27. }
  28. while (guess != answer)
  29. {
  30. tmp++;
  31. if (tmp == numPlayers)
  32. {
  33. tmp = 0;
  34. rounds++;
  35. }
  36. guess = r.nextInt(10);
  37. }
  38. String winner = "";
  39.  
  40. System.out.println("\nWinner is " + winner
  41. + "! Correctly guessed the number " + answer + " in " + rounds
  42. + " rounds.");
  43. }
  44. }
Add Comment
Please, Sign In to add comment