JAVA第一阶段基础测试题,java变量,运算符,分支,循环测试题(精)

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

JAVA第一阶段基础测试题

提示:本题为第一阶段,JAVA基础部分练习题,包括变量,运算符,分支结构,循环结构和最基本的冒泡排序,适合初学者对第一阶段的知识进行测试,以便查漏补缺。

1.

序列[15, 67, 26, 43, 61, 25, 84, 80, 34, 70]进行冒泡排序时,第三趟排序的结果是:()。

A.[15, 26, 43, 61, 25, 67, 80, 34, 70, 84]

B.[15, 26, 25, 43, 61, 34, 67, 70, 80, 84]

C.[15, 26, 43, 25, 61, 67, 34, 70, 80, 84]

D.[15, 25, 26, 43, 34, 61, 67, 70, 80, 84]

正确答案:B解析:

2.

请看下列代码: public int list(String id){ return 0; } list方法的使用正确的是:()。

A.int count=list(1002);

B.String count=list(1002);

C.int count=list("s1001");

D.String count=list("s1001");

正确答案:C解析:

3.

请看下列代码:

public static void main(String[] args) {

int[] list ={10,55,78,34,23,5,67};

for(int i=0;i<《插入代码1》;i++){

System.out.println(《插入代码2》);

}

}

如果上述代码的作用为遍历数组中的每一个元素,将其输出到控制台,那么《插入代码1》处和《插入代码2》处,应填入的代码分别为:()。

A.list.size和list

B.list.size和list[i]

C.list.length和list

D.list.length和list[i]

正确答案:D解析:

4.

下列代码段编译和运行的结果是:()。

public static void main(String[] args) {

int result=0;

for (int i=0; i <= 10; i++) {

if (i > 5){

break;

}

result+=i;

}

System.out.println(result);

}

A.输出50

B.输出15

C.输出10

D.编译错误

正确答案:B解析:

5.

下列程序编译或运行的结果是:()。public static void main(String args[]) { int width = 50;

int height;

int result;

if (width > 40) {

right = 9;

}

result = width + height;

System.out.println(result); }

A.输出:10

B.输出:19

C.输出:9

D.编译出错

正确答案:D解析:

6.

下列语句的输出结果是:()。 1

System.out.println(5+7+"tarena"+5+7);

A.12tarena57

B.57tarena12

C.57tarena57

D.12tarena12

正确答案:A解析:

7.

下面代码的输出结果是:()。 public static void main(String[] args) { int s1 = 50; int s2 = 30;

s1 = s1 + s2;

s2 = s1 - s2;

s1 = s1 - s2;

System.out.println(s1 + "," + s2);

}

A.50,30

B.30,50

C.50,80

D.80,30

正确答案:B解析:

8.

请看下列代码的输出结果是:()。

public static void main(String[] args) {

double opr = 0;

int compare = opr > 0 ? 1 : (opr < 0 ? -1 : 0);

System.out.println("f(" + opr + ")=" + compare); }

A.f(0.0)=1

B.f(0.0)=-1

C.f(0.0)=0

D.f(0.0)=-2

正确答案:C解析:

9.

以下程序的输出结果为:

public static void main(String args[]) {

int a=10;

int b=20;

boolean flag=a++>b--&&b++>a--;

System.out.println(flag+",a="+a+",b="+b); }

A.false,a=11,b=19

B.false,a=10,b=20

C.true,a=11,b=19

D.true,a=10,b=20

正确答案:A解析:

10.

请看下列代码:

public void testType() {

if (isType(1)) {

System.out.println("Type");

} else {

System.out.println("Not type"); }

}

public boolean isType(int type) {

if (type == 1) {

return false;

}

return true;

}

调用testType方法,程序编译和运行的结果是:()。

A.输出:Type

B.输出:Not Type

C.代码 if (isType(1)) { 行,编译错误

D.代码 return true; 行,编译错误

正确答案:B解析:

11.

请看下列代码编译和运行的结果是:()。

public static void main(String[] args) {

int pigs = 5;

boolean isOne = true;

boolean isTwo = false;

if ((pigs == 4) && !isTwo)

System.out.print("first");

System.out.print("second ");

相关文档
最新文档