User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,530 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 2,853 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: 1920 | Replies: 3
Reply
Join Date: Aug 2004
Posts: 11
Reputation: srthomso is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
srthomso srthomso is offline Offline
Newbie Poster

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

  #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");
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2003
Location: Malaysia
Posts: 313
Reputation: red_evolve is on a distinguished road 
Rep Power: 6
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

  #2  
Aug 10th, 2004
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.
"Study the past if you would define the future" - Confucius
Reply With Quote  
Join Date: Jul 2004
Location: Pakistan
Posts: 1,673
Reputation: nanosani is an unknown quantity at this point 
Rep Power: 8
Solved Threads: 50
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

  #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  
Join Date: Aug 2004
Posts: 11
Reputation: srthomso is an unknown quantity at this point 
Rep Power: 5
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

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

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 4:30 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC