public class CheckLeapYear
{
public static void main(String[] args)
{
int year = 2025;
// Check if the year is a leap year using conditional logic
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
{
System.out.println(year + " is a leap year.");
}
else
{
System.out.println(year + " is not a leap year.");
}
}
}
2025 is not a leap year.
import java.util.Scanner;
public class CheckLeapYear
{
public static void main(String[] args)
{
// Import Scanner Class to take user input
Scanner scanner = new Scanner(System.in);
// Take input from the user
System.out.print("Enter a year: ");
int year = scanner.nextInt();
// Check if the year is a leap year using conditional logic
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
{
System.out.println(year + " is a leap year.");
}
else
{
System.out.println(year + " is not a leap year.");
}
// Close the scanner to release resources
scanner.close();
}
}
Enter a year: 2024 2024 is a leap year.
Scanner
class is imported to take user input.
year
) is declared to store the user’s input.
scanner.nextInt()
reads the input and stores it in the year
variable.
if
condition checks two scenarios:
scanner.close()
method is used to close the input stream and release resources.
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
We’re here to make our tutorials better based on your thoughts and suggestions.