• Charpter3 关于闰年测试


    一、题目要求

    判断用户输入是否为合法输入,并判断是否为闰年

    二、闰年的满足条件

    1. 每四年为一闰年
    2. 逢百年不是闰年
    3. 逢四百年为闰年

    满足优先级依次升高,例:当满足3时,若同时满足2,则按满足3的结果处理,2000年为闰年,1900年不是闰年

    三、等价类划分

      有效等价类   无效等价类
    类型 大于0的数字 小于0的数字及其它字符

     


    四、测试用例

    1.非法输入

    2.合法输入

    1. 满足条件123
    2. 满足条件12
    3. 满足条件1
    4. 不满足任何条件
    输入 输出
    !@#¥ 非法输入
    -2000 非法输入 
    2000 闰年
    2100 非闰年 
    1996 闰年
    1995 非闰年

     

     

     

     

     

     

     

    五、代码实现

    使用HTML+JavaScript实现

     1 <!DOCTYPE html>
     2 <html>
     3 <head lang="en">
     4     <meta charset="GB2312">
     5     <style>
     6         body{text-align:center}
     7         body input{
     8             font-size: large;
     9             text-align: center;
    10         }
    11         *{
    12             margin: 2px 2px;
    13             padding: 2px 2px;
    14         }
    15         #output {
    16             color: red;
    17         }
    18     </style>
    19 <body>
    20     请输入需要查询的年份&nbsp;<input type="text"  id="year" /><br/><p id="output"></p>
    21     <input type="submit" value="check" onclick="check()"/>
    22 
    23 <script>
    24     function isInt(input){
    25         var reg = /^[0-9]+$/;
    26         if( reg.test( input ) )
    27             return true;
    28         return false;
    29     }
    30 
    31     function isLeapYear(x){
    32         return ( x % 400 == 0 ) || ( x % 4 == 0 && x % 100 != 0 );
    33     }
    34 
    35     function check(){
    36         var input = document.getElementById("year").value;
    37         if( isInt(input) ){
    38             if( isLeapYear(input) ) document.getElementById("output").innerHTML="闰年";
    39             else document.getElementById("output").innerHTML="非闰年";
    40         }
    41         else document.getElementById("output").innerHTML="非法输入";
    42     }
    43 
    44 </script>
    45 </body>
    46 </html>

    六、程序截图

  • 相关阅读:
    AcWing
    AcWing
    AcWing
    AcWing
    AcWing
    2019牛客国庆集训派对day1
    模板
    2019南昌网络赛H The Nth Item 矩阵快速幂
    ACwing92 递归实现指数型枚举 dfs
    ACwing91 最短Hamilton路径 状压dp
  • 原文地址:https://www.cnblogs.com/looooops/p/4399273.html
Copyright © 2020-2023  润新知