6.28

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

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>闰年 </title>
  5. <meta charset="utf-8">
  6. </head>
  7. <body>
  8. <form>
  9. 请输入年份: <input id="year" type="text" />
  10. <span id="check"> </span>
  11. </form>
  12. <script>
  13. var input = document.getElementById( "year");
  14. var tip = document.getElementById( "check");
  15. //输入框失去焦点触发事件
  16. input.onblur = function() {
  17. var year = input.value.trim();
  18. //年份由4位数字组成
  19. if( /^\d{4}$/.test(year)) {
  20. //能被4整除却不能被100整除的年份;能被400整除的是闰年
  21. if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
  22. tip.innerHTML = "闰年";
  23. } else {
  24. tip.innerHTML = "非闰年";
  25. }
  26. } else {
  27. tip.innerHTML = "年份格式不正确请重新输入";
  28. }
  29. }
  30. </script>
  31. </body>
  32. </html>
如何通过命令提示符登入 MySQL?如何列出所有数据库?如何切换到某个数据库并在上面工作?如何列出某个数据库内所有表?如何获取表内所有 Field 对象的名称和类型?
1. mysql -u -p  
2. show databases;  
3. use dbname; 
4. show tables;  
5. describe table_name ;
一个数如果恰好等于它的因子之和,这个数就称为「完数」。例如  6=1+2+3 .编程找出 1000 以内的所有完数
  1. package test;
  2. public class Tl5 {
  3. /**
  4. * 判断是否是完数
  5. * @param a 需判断的数字
  6. * @return boolean
  7. */
  8. public static boolean test(int a) {
  9. int cup = 0;
  10. // 循环遍历,找到所有因子,并计算因子之和
  11. for ( int i = 1; i < a; i++) {
  12. if (a % i == 0)
  13. cup = cup + i;
  14. }
  15. return (cup == a);
  16. }
  17. public static void main(String[] args) {
  18. String str = "";
  19. for ( int i = 1; i < 1000; i++) {
  20. if (test(i)) {
  21. str += i + ",";
  22. }
  23. }
  24. System.out.print(str.substring( 0, str.length() - 1));
  25. }
  26. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值