Page 2 of 2 FirstFirst 12
Results 21 to 22 of 22
  1. #21
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    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.

  2. #22
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

    Default

    Quote Originally Posted by rebelchild View Post
    Again sorry to have wasted your time
    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.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Call one Java Program from another Java Program
    By rajpalparyani in forum New To Java
    Replies: 3
    Last Post: 02-14-2011, 04:13 AM
  2. Replies: 4
    Last Post: 07-30-2010, 12:25 PM
  3. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 05:32 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

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