20180628每日编程素养

JavaScript 编程题

页面上输入一个年份(需验证),判断是否是闰年(能被 4 整除,却不能被 100 整除的年份;能被 400 整除的是闰年),并且在页面上显示相应提示信息。

<!doctype html>
<html>
    <head>
        <title>闰年</title>
        <meta charset="utf-8">
    </head>
    <body>
        <form>
            请输入年份:<input id="year" type="text" />
            <span id="check"></span>
        </form>
        <script>
            var input = document.getElementById("year");
            var tip = document.getElementById("check");
            //输入框失去焦点触发事件
            input.onblur = function() {
                var year = input.value.trim();
                //年份由4位数字组成
                if(/^\d{4}$/.test(year)) {
                    //能被4整除却不能被100整除的年份;能被400整除的是闰年
                    if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
                        tip.innerHTML = "闰年";
                    } else {
                        tip.innerHTML = "非闰年";
                    }
                } else {
                    tip.innerHTML = "年份格式不正确请重新输入";
                }
            }
        </script>
    </body>

</html>


MySQL 问答题

如何通过命令提示符登入 MySQL?如何列出所有数据库?如何切换到某个数据库并在上面工作?如何列出某个数据库内所有表?如何获取表内所有 Field 对象的名称和类型?


1.mysql  -u -p

2.show databases;

3.use dbname;

4.show tables;

5.describe table_name;


Java 编程题

一个数如果恰好等于它的因子之和,这个数就称为「完数」。例如 6=1+2+3.编程找出 1000 以内的所有完数

public class Tl5 {
    public static boolean test(int a) {
        int cup = 0;
        for (int i = 1; i < a; i++) {
            if (a % i == 0)
                cup = cup + i;
        }
        return (cup == a);
    }

    public static void main(String[] args) {
        String str = "";
        for (int i = 1; i < 1000; i++) {
            if (test(i)) {
                str += i + ",";
            }
        }
        System.out.print(str.substring(0, str.length() - 1));
    }
}


猜你喜欢

转载自blog.csdn.net/monchhichl123/article/details/80845533
今日推荐