Results 1 to 9 of 9
Thread: Teaching myself Java.
- 11-25-2011, 10:47 PM #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.
-
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.
- 11-25-2011, 11:16 PM #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.
-
Re: Teaching myself Java.
- 11-25-2011, 11:27 PM #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:2002Last edited by Jsin; 11-25-2011 at 11:34 PM.
- 11-26-2011, 12:05 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?
-
Re: Teaching myself Java.
You'll have to let us know what numbers you use and what are the rules and restrictions here.
- 11-26-2011, 12:20 AM #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.
- 11-26-2011, 08:54 PM #9
Member
- Join Date
- Nov 2011
- Location
- Texas
- Posts
- 7
- Rep Power
- 0
Similar Threads
-
Servlets class not teaching servlets
By tsky in forum Java ServletReplies: 5Last Post: 04-26-2011, 10:47 PM -
Tool for teaching Java
By finsalscollons in forum New To JavaReplies: 4Last Post: 03-17-2010, 03:24 AM -
The master list of self teaching java
By fresh83 in forum New To JavaReplies: 2Last Post: 12-27-2009, 12:09 AM -
Help with Teaching software
By Doctor Cactus in forum New To JavaReplies: 3Last Post: 11-03-2008, 06:24 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks