19 February 2014

Program to check if a year is leap year or not

Create a new class with name Chk_leapyear

import java.util.Scanner;

public class Chk_leapyear {
   
    public static void main(String[] args) {
        // TODO Auto-generated method stub
       
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter a year to check if it is leap year : ");
        int year = sc.nextInt();
        System.out.println("You entered : "+year);
        if(year%100==0){
            if(year%400==0)
                System.out.println(year+" is a leap year");
            else
                System.out.println(year+" is not a leap year");
        }
        else{
            if(year%4==0)
                System.out.println(year+" is a leap year");
            else
                System.out.println(year+" is not a leap year");
        }
    }

}

Output:(Click on image to enlarge)

Program-to-check-if-a-year-is-leap-year-or-not-output
Enter the year you want to check in the output window as shown above.
(Comment if you have any doubts)

Contact Form

Name

Email *

Message *

Smooth Graphics Java

// Arrange Bricks in Game //java brick breaker game code without flickering // added game levels 1,2,3 in the game //java paddle ball ga...