Java Program to Check a Leap Year
package main;
import java.util.Scanner;
public class Leapyear {
public static void main(String[] args) {
Scanner scr=new Scanner (System.in);
System.out.println("Enter the year:");
int year = scr.nextInt();
boolean leap = false;
if(year % 4 == 0)
{
if( year % 100 == 0)
{
if ( year % 400 == 0)
leap = true;
else
leap = false;
}
else
leap = true;
}
else
leap = false;
if(leap)
System.out.println(year + " is a leap year.");
else
System.out.println(year + " is not a leap year.");
}
}
import java.util.Scanner;
public class Leapyear {
public static void main(String[] args) {
Scanner scr=new Scanner (System.in);
System.out.println("Enter the year:");
int year = scr.nextInt();
boolean leap = false;
if(year % 4 == 0)
{
if( year % 100 == 0)
{
if ( year % 400 == 0)
leap = true;
else
leap = false;
}
else
leap = true;
}
else
leap = false;
if(leap)
System.out.println(year + " is a leap year.");
else
System.out.println(year + " is not a leap year.");
}
}
Comments
Post a Comment