943,723 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2463
  • Java RSS
Aug 10th, 2004
0

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

Expand Post »
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");
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
srthomso is offline Offline
11 posts
since Aug 2004
Aug 10th, 2004
0

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

Greetings.
Java Syntax (Toggle Plain Text)
  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.
Reputation Points: 53
Solved Threads: 1
Posting Whiz
red_evolve is offline Offline
313 posts
since Jun 2003
Aug 10th, 2004
0

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

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
Team Colleague
Reputation Points: 45
Solved Threads: 56
Unauthenticated Liar
nanosani is offline Offline
1,767 posts
since Jul 2004
Aug 10th, 2004
0

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

Cheers guys - how stupid do i feel now. told ya it'd be somethin simple.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
srthomso is offline Offline
11 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: tcp-ip programming
Next Thread in Java Forum Timeline: java





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC