银符考试题库B12
现在是:
试卷总分:100.0
您的得分:
考试时间为:
点击“开始答卷”进行答题
public class Test { public static void main(String[]arg){ final StringBuffer s=new StringBuffer (" Hello"。 s.append("word"); System.out.println(s); } } |
public class Test { public static void main(String[]arg){ final StringBuffer s=new StringBuffer ("Hello"); s=new StringBuffer("Hello world"); } } |
|||||||||||||||||||||||||||||||||||||||||||||||||
运行结果为:Hello world | 运行结果为:编译期间错误 |
不同数据类型对比 | |||||||||||||||||||||||||||||||||||||||||||||||
数据类型 | 字节长度 | 范 围 | 默认值 | 包装类 | |||||||||||||||||||||||||||||||||||||||||||
int | 4 | [-2147483648,2147483647] (-231~231-1) |
0 | Integer | |||||||||||||||||||||||||||||||||||||||||||
short | 2 | [-32768,32767] | 0 | Short | |||||||||||||||||||||||||||||||||||||||||||
long | 8 | [-9223372036854775808, 9223372036854775807] (-263~263-1) |
0L或0l | Long | |||||||||||||||||||||||||||||||||||||||||||
byte | 1 | [-128,127] | 0 | Byte | |||||||||||||||||||||||||||||||||||||||||||
float | 4 | 32位IEEE754单精度范围 | 0.0F或0.0f | Float | |||||||||||||||||||||||||||||||||||||||||||
double | 8 | 64位IEEE754双精度范围 | 0.0 | Double | |||||||||||||||||||||||||||||||||||||||||||
char | 2 | Unicode[0,65535] | u0000 | Character | |||||||||||||||||||||||||||||||||||||||||||
boolean | 1 | true和false | false | Boolean |
自动类型转换的规则 | ||||||||||||||||||||||||||||||||||||||
操作数1的类型 | 操作数2的类型 | 转换后的类型 | ||||||||||||||||||||||||||||||||||||
long | byte short char int | long | ||||||||||||||||||||||||||||||||||||
int | byte short char | int | ||||||||||||||||||||||||||||||||||||
float | byte short int char long | float | ||||||||||||||||||||||||||||||||||||
double | byte short int long char float | double |
强制类型转换的规则 | ||||||||||||||||||||||||||||||
原操作数的类型 | 转换后操作数的类型 | |||||||||||||||||||||||||||||
byte | char | |||||||||||||||||||||||||||||
char | byte char | |||||||||||||||||||||||||||||
short | byte char | |||||||||||||||||||||||||||||
int | byte short char | |||||||||||||||||||||||||||||
long | byte short char int | |||||||||||||||||||||||||||||
float | byte short char int long | |||||||||||||||||||||||||||||
double | byte short char int long double |
运算符的优先级 | |||||||||||||||||||||||||||||||||||||||||||||
优先级 | 运算符 | 结合性 | |||||||||||||||||||||||||||||||||||||||||||
1 | . () [] | 从左向右 | |||||||||||||||||||||||||||||||||||||||||||
2 | +(正) -(负) ++ -- ~ ! | ||||||||||||||||||||||||||||||||||||||||||||
3 | * / % | ||||||||||||||||||||||||||||||||||||||||||||
4 | +(加) -(减) | ||||||||||||||||||||||||||||||||||||||||||||
5 | << >>(无符号右移) >>>(有符号右移) | ||||||||||||||||||||||||||||||||||||||||||||
6 | < <= > >= instanceof | ||||||||||||||||||||||||||||||||||||||||||||
7 | == != | ||||||||||||||||||||||||||||||||||||||||||||
8 | & | ||||||||||||||||||||||||||||||||||||||||||||
9 | | | ||||||||||||||||||||||||||||||||||||||||||||
10 | ^ | ||||||||||||||||||||||||||||||||||||||||||||
11 | && | ||||||||||||||||||||||||||||||||||||||||||||
12 | | | | ||||||||||||||||||||||||||||||||||||||||||||
13 | ?: | ||||||||||||||||||||||||||||||||||||||||||||
14 | = += -= *= /= %= &= =|= ^= ~= <<= >>= >>>= |
floor、round与ceil的区别 | |||||||||||||||||||||||||||||||||||||||
数 字 | Math.floor方法 | Math.round方法 | Math.ceil方法 | ||||||||||||||||||||||||||||||||||||
1.4 | 1.0 | 1 | 2.0 | ||||||||||||||||||||||||||||||||||||
1.5 | 1.0 | 2 | 2.0 | ||||||||||||||||||||||||||||||||||||
1.6 | 1.0 | 2 | 2.0 | ||||||||||||||||||||||||||||||||||||
-1.4 | -2.0 | -1 | -1.0 | ||||||||||||||||||||||||||||||||||||
-1.5 | -2.0 | -1 | -1.0 | ||||||||||||||||||||||||||||||||||||
-1.6 | -2.0 | -2 | -1.0 |
正确的写法 | 错误的写法 | |||||||||||||||||||||||||||||||||
try{ //access db code }catch(SQLException e1){ //deal with this exception }catch(Exception e2){} |
try{ //access db code }catch(Exception e1){ //deal with this exception }catch(SQLException e2){} |