Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Would this work (https://www.askmehelpdesk.com/showthread.php?t=140928)

  • Oct 15, 2007, 10:41 AM
    albear
    would this work
    A year is a leap year if it is exactly divisible by 4, unless it is exactly divisible by 100 in which case it is only a leap year if it is exactly divisible by 400.
    Design, implement and test a program to input a year and output whether it is a leap year.

    import java.util.*;
    public class LeapYear
    {
    public static void main(String[] args)
    {
    Scanner kybd = new Scanner(System.in);

    System.out.println("Enter A Year");

    int Year;
    Year=kybd.nextInt();

    if ((Year%4)=0)
    System.out.println("The year" + Year + "is a leap year");
    else
    System.out.println("The year is not a leap year");

    }
    }


    I'm not sure, because of the info about being divisible by 100 part.
  • Oct 15, 2007, 10:54 AM
    albear
    If anybody has any ideas at all, just something I could try
  • Oct 15, 2007, 11:23 AM
    albear
    I have this now but I'm not sure how to incorporate the fact that dividing won't work, without the division by 4 working at the same time,

    import java.util.*;
    public class LeapYear
    {
    public static void main(String[] args)
    {
    Scanner kybd = new Scanner(System.in);

    System.out.println("Enter A Year");

    int Year;
    Year=kybd.nextInt();

    double LYear1;
    LYear1=(Year%4);

    double LYear2;
    LYear2=(Year%400);

    if ((LYear1=0)||(LYear2=0))
    System.out.println("The year" + Year + "is a leap year");
    else
    System.out.println("The year is not a leap year");

    }
    }

    plus it says I can't use '||' with a double so any ideas there would be great
  • Nov 14, 2007, 09:24 PM
    qcumber
    use the double equal sign (==) instead of single (=)

  • All times are GMT -7. The time now is 02:25 AM.