Advertisement
Guest User

guess game

a guest
Jan 21st, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String args[]) {
  5. playGame();
  6. }
  7.  
  8. public static int randomNumber() {
  9. int range = 100;
  10. int randomNumber = (int) (Math.random() * range);
  11. System.out.println(randomNumber);
  12. return randomNumber;
  13. }
  14.  
  15. public static void playGame() {
  16. int computerNumber = randomNumber();
  17. Scanner scanner = new Scanner(System.in);
  18. boolean win = false;
  19. for (int count = 0; count < 10; count++) {
  20. System.out.print("Choose your number\n");
  21. int userNumber = scanner.nextInt();
  22. if (userNumber == computerNumber) {
  23. System.out.println("win");
  24. win = true;
  25. break;
  26. }
  27. else if (userNumber < computerNumber) {
  28. System.out.println("Your number <");
  29. }
  30.  
  31. else {
  32. System.out.println("Your number >");
  33. }
  34. }
  35. if (!win){
  36. System.out.println("lose");
  37. }
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement