2017-10-31
JavaScript
下面兩個函數的返回值是一樣的嗎?爲什麼?
function foo1()
{
return {
bar: "hello"
};
}
function foo2()
{
return
{
bar: "hello"
};
}
答案:
返回對象{}他留有一個大括號跟return在同一行 返回的是object
沒在return同一行所以返回的是undefined
第二個return在瀏覽器解析時 會自動添加 分號
MySQL
用一條 SQL 語句,查詢出每門課都大於 80 分的學生姓名。
表名 student_score
name | course | score |
---|---|---|
張三 | 語文 | 81 |
張三 | 數學 | 75 |
李四 | 語文 | 76 |
李四 | 數學 | 90 |
王五 | 語文 | 81 |
王五 | 數學 | 100 |
王五 | 英語 | 90 |
答案:
select distinct name from user where name not in (select distinct name from user where score<=80);
Java
一球從 100 米高度自由落下,每次落地後反跳回原高度的一半;再落下,求它在第 10 次落地時,共經過多少米?第 10 次反彈多高?
答案:
public static void main(String[] args){
double x =100;
for (int i=1;i<=10 ;i++ ){
double a = Math.pow(2,i);
double t = 100/a;
x =x + (2*t);
System.out.println(t);
}
System.out.println("========");
System.out.println(x);
}