zoukankan      html  css  js  c++  java
  • 判断年份是否为闰年及非法数据的处理

    一、问题描述

       判断输入的年份是否为闰年

    二、功能实现

      在输入栏中输入年份,点击确认按钮,若年份为闰年,则显示“您输入的年份是闰年”,如年份非闰年,则显示“您输入的年份不是闰年”

    三、代码实现

    <html>
    <head>
    <script type="text/javascript">
    function test(){
    var input1=document.getElementById('input1').value;
    
    if input1%400==0
    {
          windows.alert("您所输入的时间为闰年")
    }
    else if (input1%100!=0&&input1%4==0)
    {
         windows.alert("您所输入的时间为闰年")
    }
    else
    {
         windows.alert("您所输入的时间不是闰年")
    }
    }
    
    
    </script>
    </head>
    
    <body>
    <input type="text" id="input1" value ="输入1" /><br/>
    <input type="button" onclick="test()" value="确定" />
    </body>
    </html>

       四、测试用例

    测试用例 输出结果
    1900 非闰年
    2005   非闰年
    3 非闰年
    400 闰年
    1804 闰年
    2000 闰年
    1987 非闰年
    1400 非闰年
    1576 闰年
  • 相关阅读:
    9 Fizz Buzz 问题
    2 尾部的零
    1 A+B问题
    递归
    互斥同步
    垃圾收集器与内存分配策略---垃圾收集算法
    10.矩形覆盖
    9.变态跳台阶
    8.跳台阶
    9.path Sum III(路径和 III)
  • 原文地址:https://www.cnblogs.com/Lucasleiva/p/4396516.html
Copyright © 2011-2022 走看看