Q. Write a java program that check whether a given year is a leap year.The program should prompt the user to enter a year and then determine if the year is a leap year or not.

java Leap Year program

				
					import java.io.Console;
class leap
{
	public static void main(String arg[])
	{
		Console c=System.console();
		System.out.println("Enter any yaer");
		String s =c.readLine();
		int n=Integer.parseInt(s);
		if(n%4==0&&(n%100!=0 || n%400==0))
		{
			System.out.print(n +" This is a leap yaer");

		}
		else
		{
			System.out.print(n +" This is not leap yaer");
		}
	}
}
				
			

Out Put

Employee Hierarchy:

				
					import java.util.Scanner;

public class LeapYear {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a year: ");
        int year = scanner.nextInt();
        
        if (isLeapYear(year)) {
            System.out.println(year + " is a leap year.");
        } else {
            System.out.println(year + " is not a leap year.");
        }
        
        scanner.close();
    }
    
    public static boolean isLeapYear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
    }
}

				
			
prime number

A leap year is a year that contains an additional day, typically occurring once every four years, to keep the calendar year synchronized with the astronomical year. This additional day, known as a leap day, is inserted into the calendar in order to compensate for the fact that the Earth’s orbit around the Sun is not precisely 365 days long.

1. **Purpose**: The main purpose of adding a leap day is to ensure that the calendar year remains aligned with the seasonal year, which is approximately 365.24 days long. Without leap years, the calendar would gradually drift out of sync with the seasons.

2. **Leap Year Rule**: The rules for determining whether a year is a leap year are as follows:
– A year is a leap year if it is divisible by 4.
– However, if the year is divisible by 100, it is not a leap year, unless it is also divisible by 400.

3. **Examples**:
– 2020 was a leap year because it is divisible by 4.
– 1900 was not a leap year because although it is divisible by 4, it is also divisible by 100 and not divisible by 400.
2000 was a leap year because it is divisible by both 4 and 400.

4. **Consequences**: Leap years affect the length of the calendar year, making it 366 days long instead of the usual 365 days. The extra day, February 29th, is added to the end of February.

5. **History**: The concept of leap years has been around for thousands of years, with different cultures and civilizations adopting various methods for reconciling the calendar with the solar year. The modern system of leap years, based on the Gregorian calendar, was introduced by Pope Gregory XIII in 1582.

Leap years are an important feature of the calendar system, ensuring that our calendar remains accurate and aligned with the changing seasons over long periods of time. They are essential for coordinating human activities, such as agriculture and commerce, with the cycles of nature.

 
Scroll to Top