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.


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
    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
    Eastern Florida
    Thanked 2,635 Times in 2,585 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, 08: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, 04:19 PM
  5. [SOLVED] if statement issue
    By Elementality in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 17th, 2011, 03:29 PM

Tags for this Thread