1. Member
Join Date
Nov 2011
Location
Texas
Posts
7
Rep Power
0

## Teaching myself Java.

Hello guys,

I'm teaching myself Java and I am at the end of chapter 3 in Introduction to Java Programming. 8th ed. by Y. Daniel Liang. I am working on one of the programming exercises and I am having an issue with this.

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

I don't think my use of parentheses and square brackets are correct, but I have played around with for a while and still don't know where my errors are.

Thanks for the help.

2. ## 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.

3. Member
Join Date
Nov 2011
Location
Texas
Posts
7
Rep Power
0

## 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.

4. ## Re: Teaching myself Java.

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.

5. Member
Join Date
Nov 2011
Location
Texas
Posts
7
Rep Power
0

## 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
Last edited by Jsin; 11-26-2011 at 12:34 AM.

6. Member
Join Date
Nov 2011
Location
Texas
Posts
7
Rep Power
0

## 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?

7. ## Re: Teaching myself Java.

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

8. Member
Join Date
Nov 2011
Location
Texas
Posts
7
Rep Power
0

## 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.

9. Member
Join Date
Nov 2011
Location
Texas
Posts
7
Rep Power
0

## 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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•