瑞年的判断条件:某年能被400整除 或者 某年不能被100整除但可以被4整除
(自己练习用的,暂不考虑程序的健壮性,仅实现个功能,后续可以修改补充)
python:
>>> def IsRy(x):
if x%400==0:
print x,'年是瑞年!'
elif (x%100!=0 and x%4==0):
print x,'年是瑞年!'
else:
print x,'年是平年!'
>>> IsRy(2000)
2000 年是瑞年!
>>> IsRy(1993)
1993 年是平年!
>>> IsRy(1994)
1994 年是平年!
>>> IsRy(1992)
1992 年是瑞年!
import java.util.Scanner; //要用到Scanner这个类,用来读取控制台输入
public class test
{
public void IsRY(String y)
{
int year=Integer.parseInt(y); //将string类型转换为int型
if ((year%400==0)||(year%100!=0&year%4==0))
System.out.print(y+"年是瑞年!");
else
System.out.print(y+"年是平年!");
}
public static void main(String[] args)
{
System.out.print("请输入年份:");
Scanner ob=new Scanner(System.in);
test cob=new test(); //创建类test的对象
cob.IsRY(ob.nextLine()); //调用函数IsRY,参数是获取控制台输入的数据
}
}