wood burning stoves*
The moose likes Beginning Java and the fly likes Between 1 & 100? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Between 1 & 100?" Watch "Between 1 & 100?" New topic
Author

Between 1 & 100?

joe kane
Greenhorn

Joined: Jan 26, 2004
Posts: 29
Hy everyone,
Im try to valadate a input dialog: so that the value can only be between 1 & 100.

As you can see its valadated so that only numbers can be entered....Could you please show me how this is done....
Thanks in advance joe kane
joe kane
Greenhorn

Joined: Jan 26, 2004
Posts: 29
choice1 is a String....
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
int value = Integer.parseInt(choice1);
boolean between1And100 = (value >= 1) && (value <= 100);
You'll need to catch the possible NumberFormatException.
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
Originally posted by joe kane:
Hy everyone,
Im try to valadate a input dialog: so that the value can only be between 1 & 100.

As you can see its valadated so that only numbers can be entered....Could you please show me how this is done....
Thanks in advance joe kane

Billybob Marshall has already explained that easiest is to convert the string to an int & check that the int is between 1 & 100.
I want to point out that you don't need a while loop to test if choice is null. You can do this with an if statement.


Ever Existing, Ever Conscious, Ever-new Bliss
joe kane
Greenhorn

Joined: Jan 26, 2004
Posts: 29
Thats got it sorted thanks loads for the help...
Thanks joe Kane
joe kane
Greenhorn

Joined: Jan 26, 2004
Posts: 29

Sorry im still having a problem...
Thanks joe kane
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
while (between1And100 = false)
This is no good. between1And100 = false is an assignment statement. Here between1And100 is assigned a value of false, and this assigned value is then used to evaluate the condition of the loop, which would always be false. Perhaps you want to use the comparison operator ==.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Between 1 & 100?
 
Similar Threads
Java Help!!!!!!
Only 2 decimal places!!!!
Problem with Double!!!!!!
Valadation problem!!!!!!
Validate Integer Length