Ask Experts Questions for FREE Help !
Ask
    albear's Avatar
    albear Posts: 1,594, Reputation: 222
    Ultra Member
     
    #1

    Oct 15, 2007, 10:41 AM
    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.
    albear's Avatar
    albear Posts: 1,594, Reputation: 222
    Ultra Member
     
    #2

    Oct 15, 2007, 10:54 AM
    If anybody has any ideas at all, just something I could try
    albear's Avatar
    albear Posts: 1,594, Reputation: 222
    Ultra Member
     
    #3

    Oct 15, 2007, 11:23 AM
    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
    qcumber's Avatar
    qcumber Posts: 5, Reputation: 1
    New Member
     
    #4

    Nov 14, 2007, 09:24 PM
    use the double equal sign (==) instead of single (=)

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search


Check out some similar questions!

Live in NH, work for MA company, if relocated to work from home, what about taxes? [ 3 Answers ]

Here is the situation: I currently live in NH and work for a MA company. So far I have been filing as non-resident MA tax. I have a possibility to relocate to my home in NH instead of the office in MA. Here are my questions: 1. Will MA taxes still be deducted from my pay? 2. Should I...

How does POS retail tills work, cash registers with touch screens how do they work? [ 2 Answers ]

How does POS retail tills work, cash registers with touch screens how do they work? They are also known an point of sale and kiosks like the ones in mcdonalds or leisure centres

How does POS retail tills work, cash registers with touch screens how do they work? [ 2 Answers ]

How does POS retail tills work, cash registers with touch screens how do they work? They are also known an point of sale and kiosks like the ones in mcdonalds or leisure centres


View more questions Search