一、jQuery 编程题
null 和 undefined 的区别?
解答:
项目 | null | undefined |
---|---|---|
类型 | Null型 | Undefined型 |
typeof运算 | object | undefined |
== | true | true |
=== | false | false |
值 | 代表空值 | 当声明但未初始化时,为undefined |
二、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 as '学号',username as '姓名' from students
group by username having count(course) = 1;
三、Java 编程题
打印出所有的「水仙花数」,所谓「水仙花数」是指一个三位数,其各位数字立方和等于该数本身。例如:153 是一个「水仙花数」,因为 153=1的三次方+5 的三次方+3 的三次方。
解答:
public class Numb{
public static void main(String[] args){
Numb num = new Numb();
num.findNarcissisticNumber(100,999);
}
// 找水仙花数。
public void findNarcissisticNumber(int num1, int num2){
int total = 0;
for(int i = num1; i <= num2; i++){
int a = num / 100; // 百位
int b = num /10 % 10; // 十位
int c = num % 10; // 个位
// 判断一个数是否为水仙花数。
if(Math.pow(a,3) + Math.pow(b,3) + Math.pow(c,3) == num){
System.out.println(num + "是水仙花数!");
total++;
}
}
System.out.println(num1 + "到" + num2 + "之间共有" + total + "个水仙花数!");
}
}