Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Problem with My Leap Year Calculation

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with My Leap Year Calculation

    Hello guys ,,, how r u?
    Guys i need a quick help with my leap year calculation...

    what i did is this :

    public static boolean isLeapYear(int year) { 
     
     
        if ((year % 4 == 0) && (year % 100 !== 0) && (year % 400 == 0)) 
     
        {
        return true;
        }
     
        else if { 
        return false;
        }

    it gives me an error and says:

    missing return statement & illegal start of expression




    HELP !


  2. #2
    Member
    Join Date
    Feb 2012
    Location
    Azle/Arlington
    Posts
    31
    My Mood
    Torn
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Problem with My Leap Year Calculation

    public static boolean isLeapYear(int year) { 
     
        boolean leap = false;
     
        if ((year % 4 == 0) && (year % 100 !== 0) && (year % 400 == 0)) 
     	{
        	leap = true;
        	}
     
        return leap;
        }

    try that. it should work but i am not possitive as i do not have access to a computer with a jdk. If it does not work i shall try it at 12 ish and repost with a working code.
    Last edited by lorider93p; February 7th, 2012 at 10:46 AM.

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem with My Leap Year Calculation

    Didn't work
    the same
    illegal start of expression & it is giving me errors

  4. #4
    Member
    Join Date
    Feb 2012
    Location
    Azle/Arlington
    Posts
    31
    My Mood
    Torn
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Problem with My Leap Year Calculation

     public static boolean isLeapYear(int year) { 
     
        boolean leap = false;
     
        if ((year % 4 == 0) && (year % 100 != 0) && (year % 400 == 0)) 
     	{
        	leap = true;
        	}
     
        return leap;
        }

    The symbol == means equal to and != means not equal to and the code you had written had !== meaning not equal to equal. (doesnt make much sence in english either. )

  5. #5
    Member
    Join Date
    Feb 2012
    Location
    Azle/Arlington
    Posts
    31
    My Mood
    Torn
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Problem with My Leap Year Calculation

    you could keep your original code also it would work as long as you fix the !== to !=

Similar Threads

  1. Problem with Bearing calculation appearing as NaN
    By welshcrossy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 23rd, 2012, 11:23 AM
  2. I need calculation
    By Swiss518 in forum Loops & Control Statements
    Replies: 7
    Last Post: January 27th, 2011, 01:26 PM
  3. Leap year program
    By cyspope in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 22nd, 2010, 10:20 PM
  4. RPM Calculation
    By fobos3 in forum Algorithms & Recursion
    Replies: 2
    Last Post: September 21st, 2010, 08:53 AM
  5. SQL Time Calculation
    By r12ki in forum JDBC & Databases
    Replies: 3
    Last Post: July 31st, 2009, 03:54 AM