% problem

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

% problem

 
0
  #1
Oct 4th, 2005
Hello,

I am having a problem with %. I am trying to find all the years from 1628 to 2005 that are divisible by 15, so I did this:
  1. if((year % 15 == 0) || (year % 100 == 0) || (year == 2005)){ System.out.println("Print something");
  2. }

So the way i am thinking of this is that year will be divided by 15 and if it is divided evenly then it would have a remainder of 0. So is there something wrong with the way I am using the % or is it something else that I am not seeing.

TY
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Solved Threads: 8
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: % problem

 
0
  #2
Oct 5th, 2005
I think you need to check your program again. The logic you've posted works just fine. Except I'm not sure why you want to print out if the year is 2005 or divisible by 100 if you assignment is for years divisible by 15.

Regards,

Nate
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: % problem

 
0
  #3
Oct 5th, 2005
Ok, problem solved, it wasn't the if statement, I was actually incrementing the years twice so it was giving me some funky data, and the second incrementation was done in a weird place so I didn't see it. Thanks for the help anyways.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: % problem

 
0
  #4
Oct 6th, 2005
all the years from 1628 to 2005 .... hmmm, I would definately look into a for loop for this one

sounds like a homework problem to me
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 573
Reputation: Dark_Omen is an unknown quantity at this point 
Solved Threads: 5
Dark_Omen Dark_Omen is offline Offline
Posting Pro

Re: % problem

 
0
  #5
Oct 13th, 2005
yeah that's what i did but not wat i was having a problem with, but it was a stupid error and i thought it was with the if statement.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC