- Home
- Course Category
- Course Result
- Course Detail
Hot Line: 0124-2383121
Course Introduction
Includes
Certificate & Practice Material
Programs for practice
In the program below, we've introduced beginers to programming in java
Source Code: Check if a given year is leap year or not
# This program Checks if a given year is leap year or not
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
int year;
Scanner sc = new Scanner(System.in);
System.out.print("Enter an year: ");
int year = sc.nextInt();
if(year%4 == 0)
{
if( year%100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year%400 == 0)
System.out.println(year+" is a leap year.");
else
System.out.println(year+" is not a leap year.");
}
else
System.out.println(year+" is a leap year.");
}
else
System.out.println(year+" is not a leap year.");
}
Output
Enter a year: 1900
1900 is not a leap year.