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 2 of 2

Thread: My code condition statement issue

  1. #1
    Junior Member
    Join Date
    Jul 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My code condition statement issue

    Hello ! I started programming java a while ago and I tend to do challenges that will help in my studies.

    I am doing a leap year calculator and the parameter needs to be in range 1 -9999 else it will returned false though my code is incorrect.

    so this is my code :
       public static boolean isLeapYear(int year)
     
        {
     
            boolean result = false;
     
     
           if ( (year >= 1) && (year <= 9999) && (year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0) )
                result = true;
     
            return result;
     
        }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,333
    Thanks
    53
    Thanked 2,393 Times in 2,347 Posts

    Default Re: My code condition statement issue

    How are you trying to debug the code? I suggest using print statements that print out the values of all the subexpressions so you can see which one(s) are not evaluating the way you want.

    You may be having a problem with operator precedence. See the tutorial:https://docs.oracle.com/javase/tutor...operators.html

    Use ()s To make sure the operators are evaluated in the desired order.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. LSP: weaken pre-condition and strengthen post-condition
    By Capital in forum Object Oriented Programming
    Replies: 1
    Last Post: July 13th, 2014, 12:46 PM
  2. [SOLVED] If statement issue
    By phlegm in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 15th, 2013, 07:50 PM
  3. Replies: 2
    Last Post: June 25th, 2013, 06:33 AM
  4. [SOLVED] A Loop statement and a switch statement issue
    By sternfox in forum Loops & Control Statements
    Replies: 13
    Last Post: March 7th, 2013, 03:19 PM
  5. [SOLVED] if statement issue
    By Elementality in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 17th, 2011, 02:29 PM

Tags for this Thread