Mode Gelap

Recent in Fashion

Best Seller Books

1311110001 Input and Output Statement Leap Year

Java program to check for leap year

 sample program:

 

import java.io.*;
import java.util.Scanner;
public class TestClass {
	 public static void main(String[] args)
     { 
              Scanner sc = new Scanner(System.in); 
        int year = sc.nextInt();
		boolean leap = false;
        if(year % 4 == 0)
        {
            if( year % 100 == 0)
            {
                // year is divisible by 400, hence the year is a leap year
                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");
	}
}

Output:


1994
1994 is not a leap year
2000
2000 is a leap year
2012
2012 is a leap year
2083
2083 is not a leap year

 

Subscribe Our Newsletter

avatar
"By speaking behind my back, it means that you respect my existence enough not to act in front of my face."

Related Posts

1 Komentar

  1. import java.util.Scanner;
    import java.io.*;
    public class TestClass
    {
    public static void main(String[] args)
    {
    int year;
    Scanner sc=new Scanner(System.in);
    year=sc.nextInt();
    if(year%4==0) System.out.println(year+" is a leap year");
    else System.out.println(year+" is not a leap year");

    }
    }

    ReplyDelete

Article Top Ads

Parallax Ads

Article Center Ads

Article Bottom Ads