I have this method to see whether not the year is a leap year or not.
heres the code

i get the error missing return statement at the end.

What can i do , i can't add return true or return false, becuase that screws it up.

public boolean isLeapYear()
{ if(years % 4 == 0)
    { if(years % 100 == 0)
        { if( years % 400 == 0)
                return true;
            else
                return false;
        }   

    }   
  else 
    return false;   
}

Recommended Answers

All 5 Replies

Here is your code fully parenthesized and inside code tags.

public boolean isLeapYear() {
      if (years % 4 == 0) {
         if (years % 100 == 0) {
            if ( years % 400 == 0) {
               return true;
            } else {
               return false;
            }
         }  // what should be returned here if (years % 100 != 0) ?
      } else {
         return false;
      }
   }

This is what the compiler is complaining about.

@kramerd: Line No 9;
return true;// if it is not divisible by 100 and divisible by 4 , then its a leap year.

Hope it works =D

public boolean isLeapYear()
    { 
        boolean leap = false;
        if(years % 4 == 0)
        {
            if(years % 100 == 0)
            {
                if(years % 400 == 0)
                {
                    leap = true
                }
            }else{
                leap = true;
            }
        }
        return leap;    
    }

Hope this helps =]]

public boolean isLeapYear()
		{ 
			boolean leap = false;
			if(years % 4 == 0)
			{
				if(years % 100 == 0)
				{
					if(years % 400 == 0)
					{
						leap = true
					}
				}else{
					leap = true;
				}
			}
			return leap;	
		}

To new_programmer and Tabone3:

My response was to vikas.kethineed, so my question was intended to be answered by the original poster.

I know you were trying to help, but if you read my message more carefully you might understand that I was just explaining why the compiler complained about a missing return statement, and vikas.kethineed needs to come up with the answer alone.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.