Log in

View Full Version : Would this work


albear
Oct 15, 2007, 10:41 AM
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
Oct 15, 2007, 10:54 AM
If anybody has any ideas at all, just something I could try

albear
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
Nov 14, 2007, 09:24 PM
use the double equal sign (==) instead of single (=)