Write a program to input year and check whether it is a) a century leap year b) a century year but not a leap year c) a leap year or not Sample input: 2000 Sample output: it is a century leap year note: read this program in Java without using buffer reader
Answers
import java.util.Scanner;
public class Leap_Year
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the year to check: ");
int yr = in.nextInt();
if (yr % 4 == 0 && yr % 100 != 0)
System.out.println("It is a Leap Year");
else if (yr % 400 == 0)
System.out.println("It is a Century Leap Year");
else if (yr % 100 == 0)
System.out.println("It is a Century Year but not a Leap Year");
else
System.out.println("It is neither a Century Year nor a Leap Year");
}
}
________________________________
Answer:
import java.util.Scanner;
public class Leap_Year
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the year to check:
");
int y = int.nextint();
if (yr % 4 == 0 && yr % 100 != 0)
System.out.println("It is a Leap Year");
else if (yr % 400 == 0)
System.out.println("It is a Century Leap Year");
else if (yr % 100 == 0)
System.out.println("It is a Century Year
else if (yr % 400 == 0)
System.out.println("It is a Century Leap Year");
else if (yr % 100 == 0)
System.out.println("It is a Century Year but not a Leap Year");
else
System.out.println("It is neither a Century Year nor a Leap Year");
} }
}