RyanAllarey

GuessingGame

Nov 7th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class GuessingGame
  3. {
  4.     public static void main(String [] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         System.out.println("Welcome to the number guessing game!");
  8.         System.out.println(" ");
  9.  
  10.         System.out.println("Enter the lower limit for the numbers.");
  11.         int min = scan.nextInt();
  12.  
  13.         System.out.println("Enter the upper limit for the numbers.");
  14.         int max = scan.nextInt();
  15.  
  16.         System.out.println("Your range is from " + min + " to " + max);
  17.         System.out.println(" ");
  18.  
  19.         System.out.println("Please think of a number between that range");
  20.        
  21.         int round = 0;
  22.         while (true) {
  23.             int guess = ((min + max)/2);
  24.             System.out.println(" ");
  25.             System.out.println("Is " + guess + " your number?");
  26.             System.out.println(" ");
  27.             System.out.println("no,that number is [TooHigh],[TooLow] or [yes] that is my number!");
  28.             System.out.println(" ");
  29.             String response = scan.next();
  30.             round++;
  31.             if (response.equals("TooHigh")){
  32.                 max = guess;
  33.             } else if (response.equals("TooLow")){
  34.                 min = guess;;
  35.             } else if (response.equals("yes")){
  36.                 System.out.println("we guessed your number!");
  37.                 System.out.println(" ");
  38.                 System.out.println("That took " + round + " rounds!");
  39.                 break;
  40.             } else {
  41.                 System.out.println("u failure");
  42.             }
  43.         }
  44.     }
  45. }
Add Comment
Please, Sign In to add comment