Advertisement
IanO-B

Untitled

Dec 2nd, 2019
109
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.*;
  2. public class Main {
  3.  
  4. public static void main(String[] args) {
  5. Random r = new Random();
  6. int x = 1+r.nextInt(100);
  7. Scanner keyboard = new Scanner(System.in);
  8. int tries = 1;
  9. System.out.println("I chose a number between 1-100. You have 7 tries to guess the number.");
  10. int guess = 0;
  11. while (x != guess && tries <= 7) {
  12. System.out.println("Guess #"+(tries++)+": ");
  13. guess = keyboard.nextInt();
  14.  
  15. if (x == guess){
  16. System.out.println("You guessed it! What are the chances?");
  17. break;
  18. }
  19. else if (x > guess && tries <= 7){
  20. System.out.println("Your guess is too low.");
  21. }
  22. else if (x < guess && tries <= 7){
  23. System.out.println("Your guess is too high.");
  24. } if (tries >= 7 && x != guess){
  25. System.out.println("You didn't guess the number in 7 tries. L");
  26. }
  27.  
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement