{"id":1345,"date":"2022-03-03T07:11:04","date_gmt":"2022-03-03T07:11:04","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1345"},"modified":"2022-03-03T07:11:04","modified_gmt":"2022-03-03T07:11:04","slug":"check-leap-year","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/check-leap-year\/","title":{"rendered":"Check Leap Year"},"content":{"rendered":"\n<p>A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year is a leap year only if it is perfectly divisible by 400.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java Program to Check a Leap Year<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Main {\n\n  public static void main(String&#91;] args) {\n\n    \/\/ year to be checked\n    int year = 1996;\n    boolean leap = false;\n\n    \/\/ if the year is divided by 4\n    if (year % 4 == 0) {\n\n      \/\/ if the year is century\n      if (year % 100 == 0) {\n\n        \/\/ if year is divided by 400\n        \/\/ then it is a leap year\n        if (year % 400 == 0)\n          leap = true;\n        else\n          leap = false;\n      }\n      \n      \/\/ if the year is not century\n      else\n        leap = true;\n    }\n    \n    else\n      leap = false;\n\n    if (leap)\n      System.out.println(year + \" is a leap year.\");\n    else\n      System.out.println(year + \" is not a leap year.\");\n  }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><samp>1900 is not a leap year.<\/samp><\/code><\/pre>\n\n\n\n<p>In the above example, we are checking if the year&nbsp;<code>1900<\/code>&nbsp;is a leap year or not. Since&nbsp;<code>1900<\/code>&nbsp;is a century year (ending with 00), it should be divisible by both&nbsp;<strong>4<\/strong>&nbsp;and&nbsp;<strong>400<\/strong>&nbsp;to be a leap year.<\/p>\n\n\n\n<p>However,&nbsp;<code>1900<\/code>&nbsp;is not divisible by 400. Hence, it is not a leap year.<\/p>\n\n\n\n<p>Now, let&#8217;s change the year to&nbsp;<code>2012<\/code>. The output will be<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><samp>2012 is a leap year.<\/samp><\/pre>\n\n\n\n<p>Here,&nbsp;<code>2012<\/code>&nbsp;is not a century year. Hence, to be a leap year, it needs to be divisible by only&nbsp;<strong>4<\/strong>.<\/p>\n\n\n\n<p>Since&nbsp;<code>2012<\/code>&nbsp;is divisible by 4, it is a leap year.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A leap year is exactly divisible by 4 except for century years (years ending with 00). The century year is a leap year only if it is perfectly divisible by 400. Java Program to Check a Leap Year Output In the above example, we are checking if the year&nbsp;1900&nbsp;is a leap year or not. Since&nbsp;1900&nbsp;is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[350],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1345"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1345"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1345\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}