0

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");
}

3
Contributors
3
Replies
4
Views
13 Years
Discussion Span
Last Post by srthomso
0

Greetings.

if (age<18 || age>64)
  // do something
else
  // 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.

0

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

0

Cheers guys - how stupid do i feel now. told ya it'd be somethin simple.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.