Leap Year

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 22:- Leap Year

A leap year is a year that contains an extra day, February 29th, making it 366 days long instead of the usual 365 days. Leap years are added to keep the calendar year synchronized with the astronomical year, which is approximately 365.2422 days long.

In the Gregorian calendar, which is the calendar system used in most of the world, a year is a leap year if it meets the following conditions:

  1. The year is evenly divisible by 4.
  2. If the year is evenly divisible by 100, it is not a leap year unless it is also divisible by 400.

Here's a Java program to check if a given year is a leap year or not:

javaCopy code
import java.util.Scanner; public class LeapYearChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a year: "); int year = scanner.nextInt(); // Check if the year is a leap year boolean isLeapYear = false; if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { isLeapYear = true; } if (isLeapYear) { System.out.println(year + " is a leap year."); } else { System.out.println(year + " is not a leap year."); } scanner.close(); } }

Example output:

yamlCopy code
Enter a year: 2024 2024 is a leap year.

In the program above, we take the user input for the year and store it in the variable year. We then use the if statement to check the conditions for a leap year. If the year meets either of the conditions, we set the isLeapYear variable to true, indicating that it is a leap year. Otherwise, the variable remains false, indicating that it is not a leap year.

The program then prints the result to the console based on the value of isLeapYear.

 

Disclaimer:-

Under Section 107 of the copyright act 1976, allowance is made for fair use for purposes such as criticism, comment, news reporting, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational, or personal use tips the balance in favor of fair use.

 

5. Flow Control

Comments: 0

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?