程式設計素養-Day004
阿新 • • 發佈:2018-11-05
JavaScript 程式設計題
1.頁面上輸入一個年份(需驗證),判斷是否是閏年(能被 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 問答題
2.如何通過命令提示符登入 MySQL?如何列出所有資料庫?如何切換到某個資料庫並在上面工作?如何列出某個資料庫內所有表?如何獲取表內所有 Field 物件的名稱和型別?
1. mysql -u -p
2. show databases;
3. use dbname;
4. show tables;
5. describe table_name ;
Java 程式設計題
3.一個數如果恰好等於它的因子之和,這個數就稱為「完數」。例如 6=1+2+3.程式設計找出 1000 以內的所有完數。
package test; /** * 完數判斷 * @author CUI */ public class Tl5 { /** * 判斷是否是完數 * @param a 需判斷的數字 * @return boolean */ 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)); } }