Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package austin.dailyprogrammer;
- import java.util.Random;
- import java.util.Scanner;
- public class ReverseGuessingGame
- {
- public static void main(String [] args)
- {
- int bottom = 1, top = 100, computerNumber = 50;
- Random random = new Random();
- Scanner scanner = new Scanner(System.in);
- boolean solved = false;
- String words;
- while(!solved)
- {
- System.out.print("Is your number " + computerNumber + "? (y - Yes, h - Higher, l - Lower): ");
- words = scanner.nextLine();
- if (words.equals("y"))
- {
- System.out.println("I'm so good!");
- solved = true;
- }
- else if (words.equals("l"))
- {
- top = computerNumber - 1;
- computerNumber = random.nextInt(top - bottom + 1) + bottom;
- }
- else if (words.equals("h"))
- {
- bottom = computerNumber + 1;
- computerNumber = random.nextInt(top - bottom + 1) + bottom;
- }
- else
- System.err.println("\nStop it you joker.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement