源作者:河神啊哈
以下程序运行结果为1.Java语言是1995年发布的,发布该语言的公司是:D
A.Oracle
B.Borland
C.Microsoft
D.Sun
2.编译和运行以下代码的结果为:D
public class Hello{
public static void main(String a){
System.out.println("Hello");
}
}
A.编译错误
B.运行输出 "Hello"
C.编译无错,但运行时指示没有定义构造方法
D.编译无错,但运行时指示没有正确定义main方法
3.关于下列代码说法正确的是:CD
public static void main(String[] arr) {
int first=100;
System.out.println(first);
System.out.println(second);
first = 123.456;
}
A.编译正确
B.代码System.out.println(first);行,编译出错
C.代码System.out.println(second);行,编译出错
D.代码first = 123.456;行,编译出错
4.下列代码出错的行是:C
1) public void modify() {
2) int i, j, k;
3) i = 100;
4) while ( i >0 ) {
5) j = i * 2;
6) System.out.println (" The value of j is " + j );
7) k = k + 1;
8) i--;
9) }
10) }
A.4 B.6 C.7 D.8
5.下列程序编译或运行的结果是:D
public static void main(String[] args) {
int num = 100;
for(int i=0;i4) ? 99.9 :9));
}
A.输出结果为:value is 99.99
B.输出结果为:value is 9
C.输出结果为:value is 9.0
D.编译错误
15.下列代码的输出结果是:A
int a=10;
1010 0010
1010
0010
System.out.println(a>>2);
A.2
B.4
C.40
D.42
16.~0010101语句的执行结果为:A
A.1101010
B.0010101
C.11111111
D.10001000
17.下面代码的输出结果是 B
public class Main {
public static void main(String[] args) {
int n1 = 1;
int n2 = 2;
n1 = n1 + n2;
n2 = n1 - n2;
n1 = n1 - n2;
System.out.println(n1 + "," + n2);
}
}
A.1,2
B.2,1
C.1,3
D.3,2
18.Java语言中字符串“学Java”所占的内存空间是:C
A.6个字节
B.7个字节
C.10个字节
D.11个字节
19.下列代码段的输出结果是:D
public static void main(String[] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;
if ((x == 4) && !b2){
System.out.print("l ");
}
System.out.print("2 ");
if ((b2 = true) && b1)
System.out.print("3");
}
A.2
B.3
C.1 2
D.2 3
20.请看下列代码:B
public void testIfA() {
if(true) {
System.out.println("True");
}else{
System.out.println("Not true");
}
}
public Boolean testIfB(String str) {
return boolean.valueOf(str);
}
调用testIfA方法,程序的结果是:
A.输出Not true
B.输出True
C.代码 if (testIfB("True")) { 行,编译错误
D.代码 return Boolean.valueOf(str); 行,编译错误
21.下列语句序列执行后,k 的值是。C
int i=10, j=18, k=30;
switch( j - i )
{
case 8 : k++;
case 9 : k+=2;
case 10: k+=3;
default : k/=j;
}
A.31
B.32
C.2
D.33
22. 以下由 for 语句构成的循环执行的次数是:B
for ( int i = 0; true ; i++) ;
A.执行3次
B.无限次
C.执行1次
D.一次也不执行
23.观察以下程序段 :D
int i=1,j=10;
do{
if(i++>--j){ i= j=
continue; i= j=
}
} while(i6)
break;
}
System.out.println(i);
}
A.输出6
B.输出7
C.输出10
D.编译错误
25.下面程序的输出结果是:A
public static void main(String[] args) {
int d = 325;
int sum = 0;
while (d >0) {
int n = d % 10; 5 2 3
sum += n; 5 7 10
d /= 10; 32 3 0
}
System.out.println(sum);
}
A.10
B.12
C.5
D.32
26.关于while和do-while循环,下列说法正确的是D
A.两种循环除了格式不同外,功能完全相同
B.与do-while语句不同的是,while语句的循环至少执行一次
C.do-while语句首先计算终止条件,当条件满足时,才去执行循环体中的语句
D.与while语句不同的是,do-while语句的循环至少执行一次
27.执行完以下代码int[] x = new int[25];后,下列各项正确的是:A
A.x[24]为0
B.x[24]未定义
C.x[25]为0
D.x[0]为空
28.下列代码编译和运行的结果是:B
public static void main(String[] args) {
int[] x = { 1, 2, 3, 4, 5 };
x[3]
int[] y = x;
System.out.println(y[2]);
}
A.输出2
B.输出3
C.输出4
D.编译错误
29.下面代码的输出结果是C
public class Main {
public static void main(String[] args) {
int n = 100;
int m = 200;
System.out.println(f(n,m));
System.out.println(n);
}
public static int f(int m, int n) {
n = m+n;
return n;
}
}
A.300
300
B.100
100
C.300
100
D.100
300
30.下列代码的输出结果是:A
public static void main(String[] args) {
int[] arr = { 49, 81, 77, 1, 98,50, 0, 80, 77, 18 ,11,15};
Arrays.sort(arr);
int index = Arrays.binarySearch(arr, 80);
System.out.print(index+“ ”);
index = Arrays.binarySearch(arr, 90);
System.out.print(index);
}
A.9 -12
B.8 -11
C.8 -1
D.9 -1
31.实现对数组arry的冒泡升序排序,应填入的代码是B
以下程序运行结果为i=[30,20]j=[10,20]public static void bubbleSort(int[] arry) {
int len = arry.length;
for (int i = 1; ii; j--) {
if (arry[j]= i; j--) {
if (arry[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]1)
return 1;
else
return n * method(n - 1);
}
D.public static int method(int n) {
if (n1)
return 1;
else
return n * (n - 1);
}
33.Java语言可以跨平台的原因是:B
A.Java面向对象
B.Java虚拟机
C.Java垃圾回收机制
D.Java编译器
34.执行下列代码后,哪个结论是正确的 String[] s=new String[10];AD
A. s[9] 为 null;
B. s[9] 为 "";
C. s[0] 为 未定义
D. s.length 为 10
35.请看下列表达式不正确的是:D
A.String name2 = "Jane Doe";
B.int $age=24;
C.Double _height = 123.5;
D.double ~temp = 37.5;
36.下列选项中能正确编译的是:AB
A. public static void main(String[] args) {
int one=12;
System.out.println(one);
}
B.public static void main(String[] args) {
int one;
one=12;
System.out.println(one);
}
C. public static void main(String[] args) {
int one;
System.out.println(one);
}
D.public static void main(String[] args) {
int one;
int m=10;
if(m>0){
one=12;
}
System.out.println(one);
}
37.下列程序编译或运行的结果是:C
public static void main(String[] args) {
for(int i=0;ia[j+1]){
int number = a[j];
a[j] = a[j+1];
a[j+1] = number;
}
}
}
return a;
}
/*
* 随机生成数组的方法
*/
public static int[] RandomArr(int n){
int[] array = new int[n];
for(int i=0;iarray[i]=(int)(Math.random()*101);
}
return array;
}