第3关:PHP的运算符
编程要求
能被4整除但不能被100整除,或能被400整除的年份即为闰年。
(1),使用 year 变量保存输入的年份数据。
(2),判断该年份是否为闰年,若是,输出"xxxx年是闰年",否则输出"xxxx年不是闰年"。
输出测试
测试输入:
2000
预期输出:
2000年是闰年
参考代码:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312' />
</head>
<body>
<?php
$year=2000;
/******** Begin *********/
//²¹È«ÅжÏÌõ¼þ£¬ÅжÏÊäÈëÄê·ÝÊÇ·ñΪÈòÄê
if(($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0) {
echo $year."年是闰年";
} else {
echo $year."年不是闰年";
}
/********** End ********/
?>
</body>
</html>