问题1:
public class Quest1 {
public static void main(String[] args) {
String #name ="dannie";
int $age =13;
Double _height = 24.5;
double ~temp = 22.5;
}
}
哪两个数据正确:
A.第一项数据编译不通过
B.第二项数据编译不通过
C.第三项数据编译不通过
D.第四项数据编译不通过
答案解析:
$ 、字母、下划线开头都行,后面的可以是数字、字母、下划线,建议还是按照C的风格来吧,那样其他人都比较容易接受。
所以A,D;
问题2:
public class Quest2 {
public static void main(String[] args) {
int x=5;
boolean b1 = true;
boolean b2 = false;
if((x==4)&&!b2)
System.out.println("1");
System.out.println("2");
if((b2=true)&&b1)
System.out.println("3");
}
}
A.2
B.3
C.1 2
D.2 3
E.1 2 3
F.Compilation fails
G.An exceptional is thrown at runtime.
答案解析:
知识点1
当你if语句块的代码就一行代码{}可以省略 一行
如果多行的则{}必须有,换言之:如果if()省略{},则只有执行()之后的一句话,反之,如果没有省略{}则执行{}内的代码;
知识点2
=是赋值运算符
==是比较运算符;
==操作比较的是两个变量的值是否相等,而equals比较的是2个对象的内容
故所以选择D
package TEST;
public class Question3 {
public int getValue(){
boolean vlu =true;
boolean stting =true;
String hello ="Hello";
if(vlu||(stting&&hello=="Hello")){
return 1;
}
if(vlu&hello.equals("Hello")){
return 2;
}
}
public static void main(String[] args) {
Question3 q3 = new Question3();
System.out.println(q3.getValue());
}
}
A.1
B.2
C.Compilation fails
D.The code runs with no output
E.An exception is thrown at runtime
分析:vlu的表达式不完整,到时编译不通过;
故选择C