Java Tutorial
In java programming, this program is used to accept a year as user input and checks whether year is leap year, century year or not.
A year is a leap year if divides by 4.
If year is century year if divides by 100.
import java.util.Scanner; public class LeapYear { public static void main(String[] args){ Scanner sc=new Scanner(System.in); System.out.println("Check Leap Year, Century Year or Not"); System.out.println("-------------------------------------"); System.out.print("Enter year: "); int year = sc.nextInt(); if (year % 100 == 0){ if(year % 400 == 0){ System.out.println("Year '"+year+"' is a Century Year and a Leap Year!"); } else { System.out.println("Year '"+year+"' is a Century Year but not a Leap Year!"); } } else { if(year % 4 == 0){ System.out.println("Year '"+year+"' is a Leap Year!"); } else { System.out.println("Year '"+year+"' is not a Leap Year!"); } } } }Output:
D:\Java_Programs>javac LeapYear.java D:\Java_Programs>java LeapYear Check Leap Year, Century Year or Not ------------------------------------- Enter year: 1600 Year '1600' is a Century Year and a Leap Year! D:\Java_Programs>javac LeapYear.java D:\Java_Programs>java LeapYear Check Leap Year, Century Year or Not ------------------------------------- Enter year: 2016 Year '2016' is a Leap Year! D:\Java_Programs>javac LeapYear.java D:\Java_Programs>java LeapYear Check Leap Year, Century Year or Not ------------------------------------- Enter year: 1700 Year '1700' is a Century Year but not a Leap Year! D:\Java_Programs>javac LeapYear.java D:\Java_Programs>java LeapYear Check Leap Year, Century Year or Not ------------------------------------- Enter year: 2015 Year '2015' is not a Leap Year!
Java Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page