1.定义一个结构体变量(包括年、月、日),编写程序,要求输入年、月、日,程序能判断该年是否为闰年。(闰年的条件是符合下面两者之一: ①能被4整除,但不能被100整除; ②能被100整除,又能被400整
不瘦25斤不换头像:
为什么《Java项目案例导航》书里写的是:判断某一年是否为闰年。闰年的条件是符合下面二者之一:能被4整除,但不能被100整除;能被4整除,又能够被100整除
代码是:public class LeapYear{
public static void main(Strings args[]){
int year=1989;//method1
if((year%4==0&&year%100!=0)||(year%400= =0))
System.out.println(year+"isaleapyear.");
else
System.out.println(year+"isnotaleapyear.");
year=2000; //method2
boolean leap;
if(year%4!=0)
leap=false;
else if(year%100!=0)
leap=true;
else if(year%400!=0)
leap=false;
else
leap=true;
if(leap==true)
System.out.println(year+"isaleapyear.");
else
System.out.println(year+"isnotaleapyear.");
year=2050; //method3
if(year%4==0){
if(year%100==0){
if(year%400==0)
leap=true;
else 后面的代码不敲了
|