Re: Teaching myself Java.

It all should be parenthesis and there should be no square brackets unless you're somehow dealing with arrays but not showing us (which I doubt). If the book is showing square brackets, consider getting another book.

Re: Teaching myself Java.

The book did show brackets but it was the actual formula and not code. I did try using all parenthesis but I wasn't getting the answer I needed. Maybe my problem is else where then. Thanks for the help.

Re: Teaching myself Java.

Quote:

Originally Posted by

**Jsin** The book did show brackets but it was the actual formula and not code. I did try using all parenthesis but I wasn't getting the answer I needed. Maybe my problem is else where then. Thanks for the help.

Show us your best attempt at a code solution, your expected output and your observed output.

Re: Teaching myself Java.

Ok here is my best attempt at the code.

dayOfWeek = (day + (26*(month + 1)/10) + year + (year/4) + (century/4) + 5*century) * .07;

The answer I get is 185.01000000000002

If I do it by hand I get 150.04

day:26

month:3

year:2002

Re: Teaching myself Java.

Ok, I may have read the pseudocode wrong after doing a little more reading I think this might be the right code...

dayOfWeek = (day + (26*(month + 1)/10) + year + (year/4) + (century/4) + 5*century) %7;

Notice the end I think the code is asking for a remainder not a percentage, but my answer is still not right. Now what I am getting is a 4 when I should be getting a 3. Can anybody tell me if I am getting closer to this?

Re: Teaching myself Java.

You'll have to let us know what numbers you use and what are the rules and restrictions here.

Re: Teaching myself Java.

What I am trying to do is use the Zeller's congruence to determine the day of the week. After doing some more research I think the formula in my book might be wrong. The numbers I am using are

day:26

month:3

year:2002

and I am trying to come up with Tuesday as the answer. My main question is if I was using the parentheses and square brackets correctly.

Re: Teaching myself Java.

This is the working code.

dayOfWeek = (day + (13*(month + 1)/5) + (year%100) + ((year%100)/4) + (century/4) + 5*century) %7;

Thanks guys for the help.