Web Analytics Made Easy -
StatCounter LeapYear Help - CodingForum

Announcement

Collapse
No announcement yet.

LeapYear Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • LeapYear Help

    // Name goes here

    // A year with 366 days is called a leap year. A year is a leap year if it is
    // divisible by 4 (for example, 1980). However, since the introduction of
    // the Gregorian calendar on Oct. 15, 1982, a year is not a leap year if it
    // is divisible by 100 (for example, 1900); however, it is a leap year if it
    // is divisible by 400 (for example, 2000). Write a program asks the user for
    // a year and computes whether that year is a leap year.

    // HINTS: use the mod operator to see if a number is divisible by another.
    // Look at EvenOddTemplate.java
    //
    // You need to use a boolean variable in this program.

    // Sample outputs

    // Enter year --> 2006
    // The year 2006 is not a leap year.

    // Enter year --> 1980
    // The year 1980 is a leap year.

    // Enter year --> 1900
    // The year 1900 is not a leap year.

    // Enter year --> 2000
    // The year 2000 is a leap year.



    import learning.*;

    public class LeapYear
    {
    public static void main(String[] args)
    {
    int year;
    boolean isYear = true;

    System.out.print("Enter year-->");
    year = LearningIO.readInt();

    if(year%4==0)
    isYear = true;

    if(year%100==0)
    {
    isYear = false;
    System.out.println("The year "+ year +" is not a leap year");
    }
    else
    {
    isYear = true;
    System.out.println("The year "+ year +" is a leap year");
    }


    }
    }


    Well i got all of this........but i dont know whats wrong........it doesnt work on some of the examples .............ive worked on it for a couple of days now and i cant figure it out so if anyone knows how to fix it tell me

  • #2
    You are not testing the leap year rules in the right combination.

    if(year%4==0 && year%100!=0) isYear = true;
    else if (year%400==0) isYear = true;
    else isYear = false;
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

    Comment

    Working...
    X