944,162 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1689
  • Java RSS
Oct 4th, 2005
0

% problem

Expand Post »
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:
Java Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Oct 5th, 2005
0

Re: % problem

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
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Oct 5th, 2005
0

Re: % problem

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.
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004
Oct 6th, 2005
0

Re: % problem

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
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Oct 13th, 2005
0

Re: % problem

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.
Reputation Points: 23
Solved Threads: 6
Posting Pro
Dark_Omen is offline Offline
573 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: how to run applets?
Next Thread in Java Forum Timeline: image via java





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC