Re: help needed on inputting - tearing hair out .. please!!!
- From: "Michael Redlich" <mike@xxxxxxxxxxx>
- Date: 28 Nov 2005 10:10:25 -0800
Patrick:
Thanks for posting all the code for this application. I will
definitely evaluate by tonight.
In the meantime, you may be able to get something out of the example I
found on my CD. It was a small application that Chuck Allison
published in one of his articles a few years ago. See
http://www.freshsources.com/ for more about Chuck Allison's work. The
code is as follows:
import java.io.*;
public class HiLo
{
public static void main(String[] args) throws IOException
{
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
boolean done = false;
while(!done)
{
boolean found = false;
int lo = 1;
int hi = 100;
int guess = 0;
while(!found && lo <= hi)
{
guess = (lo + hi) / 2;
System.out.println("Is it " + guess + "?");
char r = in.readLine().toUpperCase().charAt(0);
if(r == 'H')
lo = guess + 1;
else if(r == 'L')
hi = guess - 1;
else if(r != 'Y')
System.out.println("Try again...");
else
found = true;
}
if(lo > hi)
System.out.println("You cheated!");
else
System.out.println("Your number was " + guess);
System.out.println("Want to play again?");
done = in.readLine().toUpperCase().charAt(0) != 'Y';
}
}
}
Please contact me if you have any questions...
Mike.
.
- References:
- help needed on inputting - tearing hair out .. please!!!
- From: patrick_woflian
- Re: help needed on inputting - tearing hair out .. please!!!
- From: Michael Redlich
- Re: help needed on inputting - tearing hair out .. please!!!
- From: patrick_woflian
- help needed on inputting - tearing hair out .. please!!!
- Prev by Date: Re: help needed on inputting - tearing hair out .. please!!!
- Next by Date: Re: read keyboard input and storing in an array?
- Previous by thread: Re: help needed on inputting - tearing hair out .. please!!!
- Next by thread: Re: help needed on inputting - tearing hair out .. please!!!
- Index(es):
Relevant Pages
|
|