954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

% problem

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:

if((year % 15 == 0) || (year % 100 == 0) || (year == 2005)){ System.out.println("Print something");
}

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

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

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

hooknc
Posting Whiz in Training
219 posts since Aug 2005
Reputation Points: 11
Solved Threads: 8
 

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.

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

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

paradox814
Posting Whiz
351 posts since Oct 2004
Reputation Points: 13
Solved Threads: 4
 

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.

Dark_Omen
Posting Pro
573 posts since Apr 2004
Reputation Points: 23
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You