•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 423,608 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,277 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1856 | Replies: 3
![]() |
•
•
Join Date: Aug 2004
Posts: 11
Reputation:
Rep Power: 5
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.
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access activation api blogger blogging blogs business code com combo dani daniweb data debugging development dreamweaver dropdownlist environment gdata google html ibm. news innovation it java key microsoft microsoft sdk for java microsystems module net news open openbsd platform product programming remote working reuse rss serial source sun tags trends vista web working wysiwyg xml
- Code snippets pagination not working (DaniWeb Community Feedback)
- vBulletin mod_rewrite (PHP)
- Can we Programaticall Write code in VB6.0, forms/standard module/class code window (Visual Basic 4 / 5 / 6)
- Urgent Pascal Expert Needed (Pascal and Delphi)
- Please help with a script (Visual Basic 4 / 5 / 6)
- Newbie Wants Answers........ (IT Careers and Business)
Other Threads in the Java Forum
- Previous Thread: tcp-ip programming
- Next Thread: java



Linear Mode