Cerca
Chi è online?
 67 visitatori online
Membri Iscritti
18 registrati
0 oggi
0 questa settimana
3 questo mese
Ultimo: catello

[java] Verificare se un anno è bisestile

Programmazione - java
public class Bisestile
{
public static boolean bisestile(int anno) //anno è il parametro che viene passato da un altro metodo o classe
{
boolean abis; //un boolean per verificare se è vero o falso che sia bisestile
  /*per essere bisesite necessita di soddisfare queste condizioni*/
if(anno%4==0)
{
if(anno%100==0)
{
if(anno%400==0)
{
abis=true;
}
else abis=false;
}
else abis=true;
}
else abis=false;
return abis;
}
} Significato di Anno bisestile 

 

Tags: java

Commenti
Nuovo Cerca RSS
leriktlv.blogspot.com 2010-04-23 17:45:10

io lo farei così (e ho scoperto che mi parsa 29/2 in 1/3 ...
interessante)

public static boolean leapYear(int year){

Date date =
null;
SimpleDateFormat formatter = new
SimpleDateFormat("dd/MM/yyyy";

Strin g dateStr = "29/02/"+
new Integer(year).toString();

try {
date =
formatter.parse(dateStr);
}catch(Exception e){
return
false;
}

return dateStr.equals(formatter.format(date));
}
raff0z 2010-05-07 11:15:31

scusa il ritardo della risposta ... ottimo
Commenta
Nome:
Email:
 
Titolo:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Please input the anti-spam code that you can read in the image.

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

 
Translate
Ultime dal Forum
Iscriviti al Feed

Enter your email address: