English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

// let me know if this is ryt plz.
// its really important, thnx guys..

import javax.swing.*;
public class Leap_Year
{
public static void main( String[] args)
{
string year;
int yearNumeric;

year = JOptionPane.showInputDialog(null, "Enter Any Year: ");
yearNumeric = Integer.parseInt(year);
System.out.println(yearNumeric);

if (yearNumeric/4 && yearNumeric!/100)
{
System.out.println ("This is a leap year.");
}
else
{
System.out.println("This is not a leap year.");
}
else if (yearNumeric/4 && yearNumeric/100 && yearNumeric/400)
{
System.out.println ("This is a leap year.");
}
else
{
System.out.println("This is a Leap Year.");
}
}
}

2007-08-31 22:14:30 · 3 answers · asked by agam 1 in Computers & Internet Programming & Design

3 answers

leap year when
year is divisible by 4 ( thus year % 4 == 0 )
and not divisible by 100 ( and not year %100 == 0 )
and not divisible by 400. ( and not year % 400 ==0 )

boolean isLeap = (year%4) && ! (year%100) && ! (year%400);

2007-09-01 00:19:05 · answer #1 · answered by gjmb1960 7 · 0 0

Instead if the complex condition you can use the remainder operator which is %. for example:

8%4 = 0
9%4 = 1
10%4 = 2
11%4 = 3
12%4 = 0


so you can try this condition instead:

if (yearNumeric%4 == 0)
{
System.out.println ("This is a leap year.");
}
else
{
System.out.println("This is not a leap year.");
}

2007-08-31 22:47:54 · answer #2 · answered by Twisted Hardware 2 · 0 0

This is partially correct.. Depending on the accuracy level desired it will make sense to account for leap years in Julian times too.

!/ is not an operator. You might want to check that.

http://en.wikipedia.org/wiki/Julian_calendar#Leap_year_error

2007-08-31 22:51:49 · answer #3 · answered by belman420 1 · 0 0

fedest.com, questions and answers