Home Discussion Discuss: Checking whether a year is leap or not

• ### Wrong LogicNaresh September 13, 2011 at 7:01 PM

Logic has to be if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) System.out.println("Year " + year + " is a leap year"); else System.out.println("Year " + year + " is not a leap year");

• ### Bugneeraj September 27, 2011 at 5:06 PM

this is wrong.....Because 100 is not a leap year Correct logic is if(year%400 ==0 || (year%100 != 0 && year%4 == 0)) { printf("Year %d is a leap year",year); }

• ### java Program to find a given year is leap or not? Dinesh November 1, 2011 at 2:30 AM

import java.util.Scanner; public class LeapYearOrNot { public static void main(String[] args) { int n; System.out.println("Enter the year"); Scanner sc = new Scanner(System.in); n = sc.nextInt(); if (n%4 == 0 && n%100!=0||n%400==0) { System.out.println("The given year is a leap year"); } else { System.out.println("This is not a leap year"); } } }

• ### hi,Dni November 1, 2011 at 2:35 AM

hi very thankful to u bcz by this prog i got an idea..

• ### leap yeardinesh kumar girare March 13, 2013 at 12:30 PM

the logic of leap year if(year%4==0) is perfectly not a correct logic so change these correct logic if((year%4==0)&&year%100!=0) { System.out.println("leap year"); } else { if((year%4==0)&&(year%400==0)&&(year%100==0) System.out.println("leap year"); else System.out.println("not leap year"); } } so thanks

• ### javabrycool September 21, 2012 at 7:31 AM

how to create the leap year program in java

• ### The same modified with users own input.Pritam Patra November 25, 2012 at 2:03 AM

package prix; import java.util.Scanner; public class LeapYear { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the year : "); int n = scanner.nextInt(); if (n%4==0){ System.out.println("Congratz! This is a leap year"); } else{ System.out.println("This is not a leap year"); } } }

• ### java programrishipalyadav December 3, 2013 at 10:29 PM

java program not find intheweb

Subject (*):

Related Articles
Java Tips and Examples

Checking whether a year is leap or not
Checking whether a year is leap or not   ... for checking whether a year is a leap year or not. Here, we have taken the year 2000. So...;if else" condition. As we know leap year is divided by the integer 4 and so

Java Beginners

java leap year
whether itis a leap year. Aleap year is an integer greater than 1584...(); if (year.isLeapYear(y)){ System.out.println("It is a leap year."); } else{ System.out.println("It is not a leap year

Java Tips and Examples

Leap Year Program
whether a give year is leap year or not. // Michael Maus, 22 Sept 2004 import... String leapResult; // Tell's whether it's a leap year... the user if it's a leap year or not. It uses boolean operators instead

Java-Tutorials

Determining If a Year is a Leap Year in Java
that is the leap year. This section determines whether the given year is leap year... Determining If a Year is a Leap Year in Java       Leap Year: Leap Year is the year contains

Java Beginners

leap year
leap year  how to create class for leap year. It is leap year...(); if (year.isLeapYear(y)){ System.out.println("It is a leap year."); } else{ System.out.println("It is not a leap year."); } } } Thanks

Java Beginners

leap
leap   Check the given year for leap year (Test Case: 2010, 2012 , 1900

Java Beginners

Java Leap Year Problem
Java Leap Year Problem  I need help with a writing a program in Java that creates a class Year that contains a data field that holds the number of months in a year and the number of days in a year. It should include a get method

Java Beginners

leap year logic - Java Beginners
leap year logic  hi frds.. can u give me logic for leap year..  Hi Friend, Please visit the following link: http://www.roseindia.net/java/beginners/Leapyear.shtml Thanks

General

Calendar
of the Gregoriancalendar class and also checking whether the year is leap or not and printing... format of the days for this month. We are also checking whether the year is leap or not. Description of program:  In the given example first we

Java Tips and Examples

Listing out leap years between certain period
.  As we know a leap year is divisible by 4, define an integer l=n%4. So if 'n' is divisible by 4 or l=0, then the particular year can be a leap year. For checking this, apply the if statement and if this satisfies then, the year

WebSevices Questions

help regarding creation of last year project
help regarding creation of last year project  i dont know whether i picked up the right category or not. actually m a last year bsc it student. i want to develop a website I-NAVIGATOR like the m-indicator mobile app. i want

Mobile Applications Questions

wrong year
wrong year..   I think u are using other calendar Check Settings

Java Beginners

How to calculate days in a year
How to calculate days in a year  Hi, How to calculate no of days in a year? I want a program that calculates no of days in a year by specifying year... of calculating days in a year? Thanks

Java Beginners

java program - Java Beginners
java program  program to find whether the given year is a LEAP YEAR or not?  Hello, Try the following code to check whether the year is leap year or not. public class CheckLeapYear { public static void

MySQL

Mysql Year of Date
Mysql Year of Date       Mysql Year of Date is used to return the current year of the table in database. Understand with Example The Tutorial illustrate an example from 'Mysql Year

SQL Tutorial

Mysql Date Get Year
Mysql Date Get Year       Mysql Date Get Year is the way of retrieving the current year... Year'. To understand and grasp this example, we use the following syntax

Java Beginners

name of year in chinese
name of year in chinese   hello my name kiemtheng i'm come from Cambodia, i would to write java programming to calculate a name of year for each... out put . Enter day of birth: 02 Enter month of birth: 10 Enter year of birth

SQL Tutorial

Mysql Date Add Year       Mysql Date Add Year explains to add the year to the particular... 'Mysql Date Add Year'. To graspe this example, we use Add('2008-12-15',INTERVAL 1

Java Beginners

name of year in chinese
name of year in chinese   hello my name kiemtheng i'm come from Cambodia, i would to write java programming to calculate a name of year for each birthday in Chinese but i dont know how to do.   import java.util.

JSP Servlet Questions

JSP Financial Year Table
JSP Financial Year Table  Im trying to design a financial year table...wherein the user enters the data in the table and the same is updated in backend.i have successfully desinged the page but i have certain doubts in jsp

JDBC Questions

How to check whether database exists?
How to check whether database exists?  Hi, I have to create a database in mysql. I am able to create that successfully from using JDBC. But before to creating the database, i want to check whether database exists or not? How can

Java Beginners

Checking the decimal whether comma used or not
Checking the decimal whether comma used or not  I need to check the given integer whther comma used or not. For example. If the user given 123456 The output should be like 123,456 If the user given 123,456 The output should

Java Beginners

pava program - Java Beginners
pava program  program to display whether the given year is LEAP YEAR... % 100 != 0) { System.out.println(year + " is a Leap year...) { System.out.println(year + " is a Leap year."); } // It is Divisible

Java Code Examples

Check whether the number is palindrome or not
Check whether the number is palindrome or not A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction. Here we are going to check whether the number entered by the user

PHP Questions

How to Addding 1 Year with PHP
How to Addding 1 Year with PHP  Hi, I am very fresh in PHP language. I trying to create a small application about how to adding 1 year in specific date. Please suggest me. Thanks

General
Java Beginners

Java converts any given year to Roman Numeral
Java converts any given year to Roman Numeral  Write a program that converts any given year to Roman Numeral

Date Calendar

Find whether a date will be in the current quarter or the next quarter
Find whether a date will be in the current quarter or the next quarter   I have a date - example - 22-09-2012(start date) I have to find my end date... whether the day I have selected will be on the current quarter or in the next

JDBC Questions

how to ckeck whether the date has expired - JDBC
how to ckeck whether the date has expired  i have maintained a table(in postgres sql) where i have kept the records of product,customer & the date at which the product was sold. now, i want to display the list of customer whose

Java Beginners

Add year to Date without using Calendar in java
Add year to Date without using Calendar in java  how could i add a year to a date function without using calendar functions

Tutorial Topics
Questions by Category