当前位置:文档之家› JAVA第一阶段基础测试题,java变量,运算符,分支,循环测试题(精)

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

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和listB.list.size和list[i]C.list.length和listD.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.输出50B.输出15C.输出10D.编译错误正确答案: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.输出:10B.输出:19C.输出:9D.编译出错正确答案:D解析:6.下列语句的输出结果是:()。

1System.out.println(5+7+"tarena"+5+7);A.12tarena57B.57tarena12C.57tarena57D.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,30B.30,50C.50,80D.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)=1B.f(0.0)=-1C.f(0.0)=0D.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=19B.false,a=10,b=20C.true,a=11,b=19D.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.输出:TypeB.输出:Not TypeC.代码 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 ");if ((isTwo = true) && isOne) {System.out.print("third");}}A.编译错误B.输出:thirdC.输出:first secondD.输出:second third正确答案:D解析:12.下列代码段中,循环执行的次数是:()。

public static void main(String[] args) { int words = 27;do {words--;} while (words <= 18);}A.9次B.0次C.1次D.超过9次正确答案:C解析:13.下列代码的输出结果是:()。

public static void main(String[] args) { int i = 24, j = 32, h = 58;switch (j - i) {case 7:h++;case 8:h++;case 9:h += 2;case 10:h += 3;default:h /= j;}System.out.println(h);}A.59B.61C.2D.1正确答案:C解析:14.下列代码的输出结果是:()。

public static void main(String[] args) { int one = 1, two = 10, three = 8;if (one > 2) {if (two < 5) {System.out.println("one"); } else {System.out.println("two"); }} else if (three > 5) {System.out.println("three"); } else {System.out.println("four"); }}A.oneB.twoC.threeD.four正确答案:C解析:15.下面程序的输出结果是:()。

public static void main(String[] args) { int s = 105; int result = 0;while (s > 0) {int m = s % 10;result += m;s /= 10;}System.out.println(result); }A.6B.10C.5D.20正确答案:A解析:16.关于下列代码说法正确的是:()。

public static void main(String[] args) { int words = 40;System.out.println(words); System.out.println(computers); words = 67.9;}A.编译正确B.代码System.out.println(words);行,编译出错C.代码System.out.println(computers);行,编译出错D.代码words = 67.9;行,编译出错正确答案:CD解析:17.请看下列表达式正确的是:()。

A.String ename = "Allen";B.int $words=40;C.float _top =23.9;D.double ~balance = 99.9;正确答案:AB解析:18.下列数组定义及赋值,正确的是:()。

A.byte[] arr = new byte [15];B.byte arr = new byte [20];C.byte arr[]={1,2,3,4,5};D.byte[10] arr= new byte[];正确答案:AC解析:19.请看下列代码: public static void main(String[] args) { 《插入代码》 if (isRight) { System.out.println("right!"); } } 请在《插入代码》处,填入变量isRight声明的同时,进行初始化的代码:()。

A.boolean isRight=false;B.int isRight=1;C.int isRight=0;D.boolean isRight = true;正确答案:AD解析:20.下列选项的数据类型中,能存储汉字“达”的是:()。

相关主题