20180527面试
1. 下面程序的运行结果是什么?
public class D { public static void main(String[] args) { String str1="hello"; String str2="he"+new String("hello"); System.out.println(str1==str2); } }
执行结果是 false
2. 下面程序的运行结果是什么?
public class Test { public static String output=""; public static void foo(int i){ try { if(i==1){ throw new Exception(); } output+="1"; } catch (Exception e) { output+="2"; return ; }finally{ output+="3"; } output+="4"; } public static void main(String[] args) { foo(1); foo(0); System.out.println(Test.output); } }
执行结果是:23134
public class Test{ public static String output=" "; public static void foo(int i){ try{ if(i==1){ throw new Exception();//如果参数为1,抛出异常,进入到catch } output+="1"; }catch(Exception e){ output+="2";//如果参数为1,执行这里 return; }finally{ output+="3";//不管怎样这里都要执行 } output+="4";//这里是最后一个执行语句,抛出异常就不执行这里 } public static void main(String[] args){ foo(0);//第一次调用 foo(1);//第二次调用 System.out.println(Test.output); } } /* * 现在说下执行步骤:output的值我[]括起来 * 第一次调用foo(0):(1)参数为0,所以执行output+="1",那么output现在为[ 1]; * (2)执行到output+="3",那么output现在为[ 13]; * (3)执行到output+="4";那么output现在为[ 134] * 第二次调用foo(1):(1)执行if里面,抛出异常 * (2)进入到catch,执行output+="2",output现在为[ 1342] * (3)进入finally,执行output+="3", output现在为[ 13423] */
3. 下面的方法,当输入2 的时候返回值是什么?
public class A { public static void main(String[] args) { System.out.println(A.getValue(2)); } public static int getValue(int i){ int result=0; switch(i){ case 1: result=result+i; case 2: result=result+i*2; case 3: result=result+i*3; } return result; } }
执行 结果是 : 10
4. 下面一段代码中,执行后的结果是什么?
package demo; public class Demo { static boolean foo(char c){ System.out.print (c); return true; } public static void main(String[] args) { int i=0; for(foo('A');foo('B')&&(i<2);foo('C')){ i++; foo('D'); } } }
执行结果 :ABDCBDCB

游标:是对查询出来的结果集作为一个单元来有效的处理。游标可以定在该单元中的特定行,从结果集的当前行检索一行或多行。可以对结果集当前行做修改。一般不使用游标,但是需要逐条处理数据的时候,游标显得十分重要。
1.SELECT s_name,count(s_id) from Student group by s_name having count(s_id)>1 证查找到的都是存在2个以上(包括2)的同
名同姓的姓名及人数。 having 用来对分组后的
结果进一步限制必须更在group by 之后
2.select s_id,avg(score) as 平均成绩 from SC group by s_id having avg(score)>60

浙公网安备 33010602011771号