Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import java.util.*;
  2. public class Main {
  3. public static void main(String[] args) {
  4. Random r = new Random();
  5. int x = 1 + r.nextInt(100);
  6. Scanner keyboard = new Scanner(System.in);
  7. int tries = 1;
  8. System.out.println("GUESS THE NUMBER IM THINKING");
  9. System.out.println("Im thinking of a number between 1-100. You have 7 tries");
  10. int guess = 0;
  11. while (x != guess && tries <= 7) {
  12. System.out.print("Guess #" + (tries++) + ": ");
  13. guess = keyboard.nextInt();
  14.  
  15. if (x == guess) {
  16. System.out.println("You win! What are the odds?!?");
  17. break;
  18. } else if (x > guess && tries <= 7) {
  19. System.out.println("Sorry, you are too low.");
  20. } else if (x < guess && tries <= 7) {
  21. System.out.println("Sorry, you are too high.");
  22. }
  23. }
  24. if (tries >= 7 && x != guess) {
  25. System.out.println("Sorry, you didn\'t guess it in 7 guesses. You lose.");
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement