# JavaScript 編程題
null 和 undefined 的區別?
> undefined 類型只有一個值,即 undefined。當聲明的變量還未被初始化時,變量的默認值為 undefined。
> null 類型也只有一個值,即 null。null 用來表示尚未存在的對象,常用來表示函數企圖返回一個不存在的對象。
---
# MySQL 編程題
表名 students
| id | sno | username | course | score |
| --- | --- | --- | --- | --- |
| 1 | 1 | 張三 | 語文 | 50 |
| 2 | 1 | 張三 | 數學 | 80 |
| 3 | 1 | 張三 | 英語 | 90 |
| 4 | 2 | 李四 | 語文 | 70 |
| 5 | 2 | 李四 | 數學 | 80 |
| 6 | 2 | 李四 | 英語 | 80 |
| 7 | 3 | 王五 | 語文 | 50 |
| 8 | 3 | 王五 | 英語 | 70 |
| 9 | 4 | 趙六 | 數學 | 90 |
查詢出只選修了一門課程的全部學生的學號和姓名。
~~~
SELECT sno,username,count(course) FROM students
GROUP BY sno,username
HAVING count(course) = 1;
~~~
---
# Java 編程題
打印出所有的「水仙花數」,所謂「水仙花數」是指一個三位數,其各位數字立方和等于該數本身。例如:153 是一個「水仙花數」,因為 153=1的三次方+5 的三次方+3 的三次方。
~~~
package test;
/**
* @author CUI
*
*/
public class Test {
public static void main(String[] args) {
for (int num = 100; num < 1000; num++) {
// 個位數
int a = num % 10;
// 十位數
int b = num / 10 % 10;
// 百位數
int c = num / 100 % 10;
if (Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3) == num) {
System.out.println(num);
}
}
}
}
~~~