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

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

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.