I've made some code to reject age ranges, but cant get it working

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2004
Posts: 11
Reputation: srthomso is an unknown quantity at this point 
Solved Threads: 0
srthomso srthomso is offline Offline
Newbie Poster

I've made some code to reject age ranges, but cant get it working

 
0
  #1
Aug 10th, 2004
I've come up with some code to try and reject ages outside the range of 18 to 64, but i cant seem to find my errors or how to fix it. Feel stupid as its probably somethin easy, but i'm just learnin the language, can you help:

int age;
age = getIntFromUser(); // assume this function works correctly
if(age < 18 && > 65){
System.out.println("age is accepted: please continue");
}
else {
System.out.println("age rejected: program terminating");
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2003
Posts: 313
Reputation: red_evolve is on a distinguished road 
Solved Threads: 0
red_evolve's Avatar
red_evolve red_evolve is offline Offline
Posting Whiz

Re: I've made some code to reject age ranges, but cant get it working

 
0
  #2
Aug 10th, 2004
Greetings.
  1. if (age<18 || age>64)
  2. // do something
  3. else
  4. // do something
I think you should use the OR operator instead of AND because if it is rather impossible to get a number which is <18 and >64 altogether.


* Edit:
LOL, just saw nosani's reply right after mine. Yeah, the arrows that he mentioned is right. So, mine is the opposite, eh. You would have to print error message for the if part, and an "accepted" message for the else part.
"Study the past if you would define the future" - Confucius
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 55
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: I've made some code to reject age ranges, but cant get it working

 
0
  #3
Aug 10th, 2004
if(age < 18 && > 65){
Replace this with :
if(age > 18 && < 65){
You got the wrong arrows ... it says age less than 18 and greater than 65 is accepted ... LOL
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 11
Reputation: srthomso is an unknown quantity at this point 
Solved Threads: 0
srthomso srthomso is offline Offline
Newbie Poster

Re: I've made some code to reject age ranges, but cant get it working

 
0
  #4
Aug 10th, 2004
Cheers guys - how stupid do i feel now. told ya it'd be somethin simple.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC