Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Khema Edirisinghe
java leap year
1 Answer(s)      4 years and 2 months ago
Posted in : Java Beginners


write a java program that takes an input as a keyboard inputs or command line argument, a year between 1800 and 2000 and then reports whether itis a leap year. Aleap year is an integer greater than 1584 that is either divisible by 400 or is divisible by 4 but not 100


Advertisement
View Answers

October 23, 2010 at 11:50 AM


Hi Friend,

Try the following code:

import java.util.*;

public class LeapYear{
   public static boolean isLeapYear(int year) {

    if (year < 0) {
      return false;
    }
    if (year % 4 == 0) {
      return true;
    }  else if (year % 400 == 0) {
      return true;
    } 
    else if (year % 100 == 0) {
      return false;
    }
    else {
      return false;
    }
  }
public static void main(String[] args){
    Scanner in = new Scanner(System.in);
    System.out.println("Enter any year:" );
    int y = in.nextInt();
        LeapYear year = new LeapYear();
    if (year.isLeapYear(y)){
    System.out.println("It is a leap year.");
    }           
    else{
    System.out.println("It is not a leap year.");
    }
}
}

Thanks



Related Tutorials/Questions & Answers:
java leap year
java leap year  write a java program that takes an input... 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
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
Advertisements
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
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
Determining If a Year is a Leap Year in Java
Determining If a Year is a Leap Year in Java       Leap Year: Leap Year is the year contains an extra day. In the leap year, February month contains 29 days since normally
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
leap
leap   Check the given year for leap year (Test Case: 2010, 2012 , 1900
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
convert date month and year into word using java
convert date month and year Java  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
Retrieve all the students in the same year(Java ArrayList)?
Retrieve all the students in the same year(Java ArrayList)?  FoundStudents.jsp year- parameter I receive from a form search- is an object of type Student, with ID, name, year <% Student search = null; ArrayList<Student>
convert date month and year into word using java
convert date month and year into word using java  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
convert date month and year into word using java  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
convert date month and year into word using java  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Java Date Month Format  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Match Date format  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Date Format in Jave  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Basic format for Date and Month  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Convert Date Month format  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
Convert Date Format  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
convert date month and year into word using java
convert date month and year  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   Visit Here
Addintion in year fields of sql date in a java page
Addintion in year fields of sql date in a java page  In my database...("Year: " + simpleDateformat.format(date)); String k= simpleDateformat.format(date); } But I have to add 4 with the year value
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
convert date month and year into word using java
convert date month and year into word using java  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   import java.util.*; import java.text.
convert date month and year into word using java
convert date month and year into word using java  convert the date, month,year into word like 12-3-2012 into twelve march two thousands twelve pls send the code write in java.   import java.util.*; import java.text.
Java get Year
Java get Year       In this section, you will learn how to obtain the current year. The Calendar.... The method cal.get(Calendar.YEAR) will return the current year. Here
Write a program that converts any given year to Roman Numeral in Java
Write a program that converts any given year to Roman Numeral in Java  Write a program that converts any given year to Roman Numeral
Java get year from date
Java get year from date       In this section you will study how to retrieve the year from... showing the format of year. The method simpleDateformat.format(date) formats
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... will be a leap year. For listing out each year write "+n"
wrong year
wrong year..   I think u are using other calendar Check Settings
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
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.
 

 

 

DMCA.com