0

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

3
Contributors
4
Replies
5
Views
13 Years
Discussion Span
Last Post by Dark_Omen
0

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

0

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.

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.