• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Between 1 & 100?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
choice1 is a String....
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int value = Integer.parseInt(choice1);
boolean between1And100 = (value >= 1) && (value <= 100);
You'll need to catch the possible NumberFormatException.
 
Ranch Hand
Posts: 382
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
joe kane
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats got it sorted thanks loads for the help...
Thanks joe Kane
 
joe kane
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sorry im still having a problem...
Thanks joe kane
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ==.
 
Yes, my master! Here is the tiny ad you asked for:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic