第二章 简单数据类型
1、下列属于合法标识符的是__________。 答案:A
A)_wind B)5tie C)+file D)room#
2、下列数中,表示为八进制整数的是__________。 答案:B
A)0xB8 B)0156 C)4096L D)‘\141’
3、下列数中,表示为单精度浮点数的是__________。 答案:C
A)0.652d B)3.14156D C)0.29874f D)0568
4、作用域是整个类的变量属于__________。 答案:D
A)局部变量 B)方法参数变量 C)异常参数变量 D)类变量
5、用单引号括起来表示并占内存16为的数据类型是__________。 答案:C
A)字节型 B)短整型 C)字符型 D)不尔型
6、利用Java编译器改正下列程序的错:
public class Exercise1{
public static void main (String[] args){
int i = 97;
char j = i;
System.out.println(“j = “+j);
}
} 答案:D
A)将 int = 97;改为 int i = ‘97’ B) 将 int = 97;改为 float i = 97
C)将 int = 97;改为 long i = 97 D)将 int = 97;改为char i= 97
7、改正程序下划线处错误:
class Variable{
int x = 0,y = 0, z= 0;//类变量
void init (int x,int y){
x = x;
y = y;
int z = 5; //局部变量
System.out.println(“******在初始化中*******”);
System.out.println(“x = “ +x+” y = “+y+” z = “+z);
}
} 答案:B
A) int x = x; int y = y; B)this.x = x; this.y = y;
C)v.x = x; v.y = y ; D)this.v.x = x ; this.v.y = y;
8、改正下列程序的错误:
public class Exercise3{
public static void main (String[] args){
int i = 1000000;
short j;
j = (short) i;
System.out.println(“i = “+i);
System.out.println(“j = “+j);
}
}
要求获得以下运行结果:
i = 1000000
j = 16960 答案:B
A)将short j; j = (short) i;改为short j ; j = i*100;
B)将short j; j = (short) i;改为long j ; j = i*100;
C)short j; j = (short) i;改为byte j ; j = i*100;
D)short j; j = (short) i;改为char j ; j = i*100;