Week 1 exercise 24

341 views
Skip to first unread message

Piks

unread,
Aug 12, 2015, 4:47:23 AM8/12/15
to mooc.fi
Hi,

I'm having problems with week  1  exercise 24.


I don't understand how to indicate on the code that when the year can be divided by 100 it must also be divisible by 400.


 

Help will be much appreciated.

Best regards,

Piks


Supported languages are English and Finnish

Please use our build in TMC Pastebin when asking questions related to your code  
 
TMC Plugin has built-in code sharing feature. 
In NetBeans, select TMC -> Send code to TMC pastebin. Copy the link you receive and paste it to your message.  

You may use our web interface to share code snippets: http://paste.mooc.fi

g_un...@yahoo.com

unread,
Aug 12, 2015, 5:43:49 AM8/12/15
to mooc.fi
Hello,

First of all that is exercise 21, not 24. Please edit the title.

You can find the algorithm of the Leap year on Wikipedia:
if (year is not exactly divisible by 4) then (it is a common year)
else
if (year is not exactly divisible by 100) then (it is a leap year)
else
if (year is not exactly divisible by 400) then (it is a common year)
else (it is a leap year)


So, you can use the following formula to find out if the year is or isn't divisible with a certain number:
year%100 == 0  //is divisible to 100
year%100 != 0 // isn't divisible to 100


Kind regards,
Gabi Nan

g_un...@yahoo.com

unread,
Aug 12, 2015, 5:50:59 AM8/12/15
to mooc.fi
You algorithm is wrong.  The correct one is: if (year is divisible with 4 but it's not divisible with 100, or is divisible with 400) then it's a leap year. 


Kind regards,
Gabi Nan

Piks

unread,
Aug 12, 2015, 6:05:39 AM8/12/15
to mooc.fi
Thank you both for the help! 

This exercise is exercise #24 on my download.
Message has been deleted

elaile...@gmail.com

unread,
Aug 12, 2015, 4:32:39 PM8/12/15
to moo...@googlegroups.com
Hi, you can find the solution here:

 SOLUTION REMOVED BY ADMIN

mooc.fi

unread,
Aug 13, 2015, 3:01:31 AM8/13/15
to mooc.fi, elaile...@gmail.com
Hi,

Could you please stop posting the solutions to give others a chance to learn :)

Thank you!

Best regards
MOOC Team


On Wednesday, August 12, 2015 at 11:32:39 PM UTC+3, elaile...@gmail.com wrote:
Hi, you can find the solution here:

Joni

unread,
Aug 13, 2015, 3:07:45 AM8/13/15
to mooc.fi
Hei,

Vuosi on karkausvuosi seuraavien ehtojen mukaan:

Vuosi on jaollinen neljällä ja vuosi ei ole jaollinen sadalla. 

TAI

Vuosi on jaollinen neljällä, sadalla ja neljälläsadalla. Tässä oikeastaan riittää tarkastaa onko vuosi jaollinen neljälläsadalla sillä 4 * 100 = 400 joka väistämättä tarkoittaa vuoden olevan jaollinen neljällä ja sadalla jos vuosi on jaollinen neljälläsadalla.

Ja ehdot voit toteuttaa käyttäen && merkintää ja tai ehdot käyttäen || merkintää, muista kuitenkin käyttää sulkuja tarvittaessa.

Ystävällisin terveisin,
Joni
Reply all
Reply to author
Forward
0 new messages