Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GuessingGame
- {
- public static void main(String [] args) {
- Scanner scan = new Scanner(System.in);
- System.out.println("Welcome to the number guessing game!");
- System.out.println(" ");
- System.out.println("Enter the lower limit for the numbers.");
- int min = scan.nextInt();
- System.out.println("Enter the upper limit for the numbers.");
- int max = scan.nextInt();
- System.out.println("Your range is from " + min + " to " + max);
- System.out.println(" ");
- System.out.println("Please think of a number between that range");
- int round = 0;
- while (true) {
- int guess = ((min + max)/2);
- System.out.println(" ");
- System.out.println("Is " + guess + " your number?");
- System.out.println(" ");
- System.out.println("no,that number is [TooHigh],[TooLow] or [yes] that is my number!");
- System.out.println(" ");
- String response = scan.next();
- round++;
- if (response.equals("TooHigh")){
- max = guess;
- } else if (response.equals("TooLow")){
- min = guess;;
- } else if (response.equals("yes")){
- System.out.println("we guessed your number!");
- System.out.println(" ");
- System.out.println("That took " + round + " rounds!");
- break;
- } else {
- System.out.println("u failure");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment