Question
Write a program called thinking.java , that is like the guessing game, I am thinking of a number between blank and blank. Use a Scanner
Write a program called thinking.java , that is like the guessing game, I am thinking of a number between blank and blank. Use a Scanner to prompt the user for the lower and upper bounds of the number theyre thinking of, and correct the error if y < x (i.e. swap the numbers). Use a binary search algorithm to iteratively guess what number they are thinking of. On each guess, prompt the user to see whether your guess is less than, greater than, or equal to their number. When the user responds that the guess was correct, print the number of guesses the program made and then exit. Example output: Think of a number! Lower bound: 1 Upper bound: 100 Is it 50? [lt/eq/gt]: lt Is it 25? [lt/eq/gt]: gt Is it 37? [lt/eq/gt]: eq It took 3 guesses to find the number 37!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started