Advertisement
Guest User

CHDHSguess2

a guest
Oct 23rd, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3. public class Problem3 {
  4. public static void main(String[] args) {
  5. Random rand = new Random();
  6. int randint = rand.nextInt(50);
  7. int tries = 0;
  8. Scanner scan = new Scanner(System.in);
  9. int guess;
  10. boolean win = false;
  11. while (win == false) {
  12. System.out.println("Guess a number between 1 and 50");
  13. guess = scan.nextInt();
  14. tries++;
  15.  
  16. if (guess == randint) {
  17. win = true;
  18. }
  19. else if (guess < randint - 10) {
  20. System.out.println("You are cold, guess again.");
  21. }
  22. else if (guess > randint + 10) {
  23. System.out.println("you are cold, guess again.");
  24. }
  25. else if (guess <= randint - 10){
  26. System.out.println("you are hot, guess again.");
  27. }
  28. else if (guess <= randint + 10) {
  29. System.out.println("you are hot, guess again.");
  30. }
  31. else if (guess <= randint + 5) {
  32. System.out.println("you are VERY hot, guess again.");
  33. }
  34. else if (guess <= randint - 5) {
  35. System.out.println("you are VERY hot, Guess again.");
  36. }
  37. }
  38. System.out.println("You've won!");
  39. System.out.println("The number was " + randint);
  40. System.out.println(" it took you " + tries + " tries");
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement