java基础入坑集

坑1
public class TestDemo {
public static void main(String[] args) {
System.out.println(test("0")+","+test(null)+","+test("66"));
}
public static int test(String str){
try {
return str.charAt(0)-'0';
} catch (NullPointerException e) {
return 2;
} catch (IndexOutOfBoundsException e) {
return 3;
} catch (Exception e) {
return 4;
}finally{
return 5;
}
}
}

打印三个5,finally{}代码块里面的内容一定会运行,会产生覆盖。

str.charAt(0)-'0';改行代码返回str下标为0的字符与‘0’比较,然后如果是,返回0,否则为-1;

比如‘123’.charAt(0)-'1'是0;‘123’.charAt(0)-'1'是-1;

坑2

public class test {

public static void main(String[] args) {
int sum=0;
for(int i=0;i<10;i++){
sum=sum++;
}
System.out.println(sum);
}
}

打印的结果为0;因为是sum++,而不是++sum;

坑3

.1 查询每门课程成绩都大于80分学生的学号
数据库 表 student
name score course
A 85  语文
A 75  数学
A 82  英语
B   75  语文
B   89  数学
B   79  英语
天使美眉90 语文
天使美眉100 数学
天使美眉100 英语

请找出每门课程都超过80分的那个人名字的SQL语句

SQL1:

select name from test.stu
group by name
having count(score) =sum(case  when score>80 then 1 else 0 end )

SQL2:

select name from stu
group by name
having name not in (
select name from stu
where score <80)

SQL3:

select name from test.stu
group by name
having min(score)>=80

原文地址:https://www.cnblogs.com/wenwenzuiniucha/p/8341085.html