Wednesday, August 19, 2015

Java program to check if a year entered by user is a Leap year or not

/*
Given a year, return true if it is a leap year otherwise
return false. We can check that by noting that years that are multiples of 100 are not leap years,
unless they are also multiples of 400.
*/

import java.util.*;
public class program
{
    public static void main(String args[])
    {
        Scanner s = new Scanner(System.in);
        System.out.println("Enter the year you want to check:- ");
        int year = s.nextInt();
        if(test(year))
        {
            System.out.println("It is a leap year");
        }
        else
        {
            System.out.println("It is not a leap year");
        }
    }
    
public static boolean test(int year)
{
boolean is_divisible_by_4_and_not_by_100 = (year%4==0 && year%100!=0);
boolean divisible_by_400 = (year%400==0);
return (is_divisible_by_4_and_not_by_100 || divisible_by_400);
}

}

//Author: Mayank Rajoria


Thursday, June 25, 2015

A new blog with all my current projects!

Its been a long time since I have added any new programs to this blog and a major reason for it is that I haven't been programming in Java much lately. I moved on to C++ for competitive programming and also learnt swift for iOS development. I have now started a new blog Mayank's Corner where I now post my new updates and information about my projects. So go and give it a view!

https://mayanksworkshop.wordpress.com