作业DAY009

一、JavaScript 编程题

题目文案:null 和 undefined 的区别?

答:

null是一个表示”无”的对象,转为数值时为0;undefined是一个表示”无”的原始值,转为数值时为NaN

  • null表示”没有对象”,即该处不应该有值

(1) 作为函数的参数,表示该函数的参数不是对象。

(2) 作为对象原型链的终点。

  • undefined表示”缺省值”,就是此处应该有一个值,但是还没有定义

(1)变量被声明了,但没有赋值时,就等于undefined。

(2) 调用函数时,应该提供的参数没有提供,该参数等于undefined。

(3)对象没有赋值的属性,该属性的值为undefined。

(4)函数没有返回值时,默认返回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

查询出只选修了一门课程的全部学生的学号和姓名。

答:(1)SQL语句如下:

SELECT sno,username,count(course) FROM students
GROUP BY sno,username
HAVING count(course) = 1;

       (2)结果截图:

三、Java 编程题

题目文案:打印出所有的「水仙花数」,所谓「水仙花数」是指一个三位数,其各位数字立方和等于该数本身。例如:153 是一个「水仙花数」,因为 153=1的三次方+5 的三次方+3 的三次方。

答:(1)代码
package package1;

public class count {
    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);
            }
        }
    }
}
       (2)结果截图

猜你喜欢

转载自www.cnblogs.com/fighting2015/p/11306739.html
009