Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
California State Polytechnic University, Pomona
Computer Science Department
CS 240 Spring 2014
Laboratory Exercise: Number Guessing Game Friday, May 16 2014
Write a Java program that will correctly guess an arbitrary positive integer value n that
you have chosen using O(log n) iterations. Use doubling until you have determined a search
range, and then use binary search to determine the exact value. (Incidentally, you can use
this method to impress your friends by guessing any number they have chosen in the fewest
steps!) Here is an example of this method at work:
$ java OpenSearch 123
Choice=123
low=0 high=1
low=0 high=2
low=0 high=4
low=0 high=8
low=0 high=16
low=0 high=32
low=0 high=64
low=64 high=128
guess=96 low=64 high=128
guess=112 low=97 high=128
guess=120 low=113 high=128
guess=124 low=121 high=128
guess=122 low=121 high=123
guess=123 low=123 high=123
Answer=123
Success!
Demonstrate your code to me in the lab for the numbers 123, 2468, 4096 and 31415926.
Submit your code and output on Blackboard.