| | |
I've made some code to reject age ranges, but cant get it working
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2004
Posts: 11
Reputation:
Solved Threads: 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");
}
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");
}
Greetings.
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.
Java Syntax (Toggle Plain Text)
if (age<18 || age>64) // do something else // do something

* 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
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
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
![]() |
Similar Threads
- Help with some loops and SQL (PHP)
- New to C program code to calculate age (C)
- Need help with DirectX code (C)
Other Threads in the Java Forum
- Previous Thread: tcp-ip programming
- Next Thread: java
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor






