Results 21 to 22 of 22
Thread: annualCalendar Java Program
- 04-07-2011, 02:30 PM #21
Senior Member
- Join Date
- Jun 2008
- Posts
- 339
- Rep Power
- 5
I think the forum members are frustrated because your misunderstanding isn't a Java issue, but simple logic. It's easy to get confused trying to write code without having first figured out the logic of what you need to do.
It would be a lot easier to follow if you put your switch's 'case' statements in order, i.e. case 2 for February should come after case 1 and before case 3, but in any case, you don't need a switch to check the leap year - the month is always going to be February, month 2.
So your logic should be: if currentMonth is 2 then check for a leap year.
Your leapYear boolean needs to be declared where it can be accessed later (i.e. not inside a 'case' block), and initialised to 'false'. When you do the leap year check, assign the result to the leapYear boolean.Last edited by dlorde; 04-07-2011 at 02:32 PM.
- 04-07-2011, 11:24 PM #22
You only waste our time if you don't think or learn. In my experience many n00bs will hack away at some code without thinking. Then whine when it doesn't compile and/or just continue to try random things. Another common mistake is when they try something the correct and it produces more errors (like you did with an if statement) they assume that it is completely wrong and revert back to what they had previously. The correct action would have been to post their code and error messages and ask for help. Coding is about precision. You cannot just mangle some code together and hope it works. You need to think logically about how to do things. Once you have the logic clear in your head, the code comes much easier.
Similar Threads
-
Call one Java Program from another Java Program
By rajpalparyani in forum New To JavaReplies: 3Last Post: 02-14-2011, 04:13 AM -
Is There A Way To Call Another Java Program Within A Java Program
By SwissR in forum New To JavaReplies: 4Last Post: 07-30-2010, 12:25 PM -
execute java program within java program
By popey in forum New To JavaReplies: 2Last Post: 10-22-2009, 05:32 PM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks