第一次考试——java基础测试

来源:互联网 发布:苏州网络培训 编辑:程序博客网 时间:2024/06/06 01:21

紧张的十天时间一晃而过,让人犯运的OO,继承,构造器……不过,测试题还是很简单,100分,嘿嘿!


1.关于Java语言的特征,描述正确的是  A
A. 支持跨平台(Windows,Linux,Unix等)
B. GC(自动垃圾回收),提高了代码安全性
C. 支持类似C的指针运算操作
D. java语言是面向对象的语言

2.下列表达式正确的是  C
A. byte b=128;
B. boolean b=null;
C. long a = 2147483648L;
D. float f=0.9239;
3.下列不属于java标识符的是  E (java中可以用下划线和$字母开头,但不能用数字开头,)
A.HelloWorld
B._HelloWorld
C. $HelloWorld
D. HelloWorld3
E. 3HelloWorld

4.下列代码的运行结果是: 8
public class SwitchTest {
public static void main (String []args) {
System.out.println (“value =” +switchIt(4));
}
public static int switchIt(int x) {
int j = 1;
switch (x) {
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default:j++;
}
return j + x;
}
5.以下程序的输出结果为:A
public class test {
 public static void main(String args[]) {
 int x=1,y=1,z=1;
 if (x--==1&&y++==1||z++==1)
 System.out.println("x="+x+",y="+y+",z="+z);
 }
}
A. x=0,y=2,z=1
B. x=1,y=2,z=1
C. x=0,y=1,z=1
D. x=0,y=2,z=2

6.下面的程序没有编译错误的是:D
A. public class Main{
public static void main(String[] args) {
byte b1 = 1;
byte b2 = 2;
byte b = b1+b2;  (byte b=byte(b1+b2))
}
}
B. public class Main{
public static void main(String[] args) {
int n;      //变量必须初始化
for(int i=0;i<10;i++) {
n +=i;
}
}
}
C. public class Main{
public static void main(String[] args) {
int n = 100;
for(;;) {    //没有退出循环的条件,编译器会认为是死循环
}
System.out.println(n);
}
}
D. public class Main{
public static void main(String[] args) {
int n = 100;
while(n>0);
System.out.println(n);
}
}

7.执行完以下代码int [ ] x = new int[25];后,下列各项正确的是: A
A、 x[24]为0
B、 x[24]未定义
C、 x[25]为0
D、 x[0]为空
 8.下面程序的输出结果是: A
public static void main(String[] args) {
 int d = 325;
 int sum = 0;
 while (d > 0) {
 int n = d % 10;
 sum += n;
 d /= 10;
 }
 System.out.println(sum);
}
A. 10
B. 12
C. 5
D. 32

9.char类型的整数范围是  B
A. 0 ... 32767
B. 0 ... 65535
C. –256 ... 255
D. –32768 ... 32767

10.实现对数组arry的冒泡升序排序,应填入的代码是 B
public static void bubbleSort(int[] arry) {
 int len = arry.length;
 for (int i = 1; i < len; i++) {
 boolean asc = true;
 < 填入代码 >
 if (asc) return;
 }
}
private static void swap(int[] arry, int i, int j) {
 int temp = arry[i];
 arry[i] = arry[j];
 arry[j] = temp;
}
A. for (int j = len-1; j > i; j--) {
if (arry[j] < arry[j - 1]) {
swap(arry, j, j - 1);
asc = false;
}
}
B. for (int j = len - 1; j >= i; j--) {
if (arry[j] < arry[j - 1]) {
swap(arry, j, j - 1);
asc = false;
}
}
C. for (int j = len - 1; j >= i; j--) {
if (arry[j] > arry[j - 1]) {
swap(arry, j, j - 1);
asc = false;
}
}
D. for (int j = len - 1; j >= i; j--) {
if (arry[j] < arry[j - 1]) {
swap(arry, j, j - 1);
asc = true;
}
}
原创粉丝点击