JAVA第一阶段基础测试题java变量运算符分支循环测试题Word下载.docx
《JAVA第一阶段基础测试题java变量运算符分支循环测试题Word下载.docx》由会员分享,可在线阅读,更多相关《JAVA第一阶段基础测试题java变量运算符分支循环测试题Word下载.docx(10页珍藏版)》请在冰豆网上搜索。
int[]list={10,55,78,34,23,5,67};
for(inti=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.
下列代码段编译和运行的结果是:
intresult=0;
for(inti=0;
i<
=10;
i++){
if(i>
5){
break;
result+=i;
System.out.println(result);
A.输出50
B.输出15
C.输出10
D.编译错误
5.
下列程序编译或运行的结果是:
publicstaticvoidmain(Stringargs[]){
intwidth=50;
intheight;
intresult;
if(width>
40){
right=9;
result=width+height;
A.输出:
10
B.输出:
19
C.输出:
9
D.编译出错
6.
下列语句的输出结果是:
1
System.out.println(5+7+"
tarena"
+5+7);
A.12tarena57
B.57tarena12
C.57tarena57
D.12tarena12
A解析:
7.
下面代码的输出结果是:
ints1=50;
ints2=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
8.
请看下列代码的输出结果是:
doubleopr=0;
intcompare=opr>
0?
1:
(opr<
-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
9.
以下程序的输出结果为:
inta=10;
intb=20;
booleanflag=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
10.
publicvoidtestType(){
if(isType
(1)){
Type"
}else{
Nottype"
publicbooleanisType(inttype){
if(type==1){
returnfalse;
returntrue;
调用testType方法,程序编译和运行的结果是:
Type
NotType
C.代码if(isType
(1)){行,编译错误
D.代码returntrue;
行,编译错误
11.
请看下列代码编译和运行的结果是:
intpigs=5;
booleanisOne=true;
booleanisTwo=false;
if((pigs==4)&
!
isTwo)
System.out.print("
first"
second"
if((isTwo=true)&
isOne){
third"
A.编译错误
third
firstsecond
D.输出:
secondthird
12.
下列代码段中,循环执行的次数是:
intwords=27;
do{
words--;
}while(words<
=18);
A.9次
B.0次
C.1次
D.超过9次
13.
下列代码的输出结果是:
inti=24,j=32,h=58;
switch(j-i){
case7:
h++;
case8:
case9:
h+=2;
case10:
h+=3;
default:
h/=j;
System.out.println(h);
A.59
B.61
C.2
D.1
14.
intone=1,two=10,three=8;
if(one>
2){
if(two<
5){
one"
two"
}elseif(three>
three"
four"
A.one
B.two
C.three
D.four
15.
下面程序的输出结果是:
ints=105;
intresult=0;
while(s>
0){
intm=s%10;
result+=m;
s/=10;
A.6
B.10
C.5
D.20
16.
关于下列代码说法正确的是:
intwords=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.Stringename="
Allen"
;
B.int$words=40;
C.float_top=23.9;
D.double~balance=99.9;
AB解析:
18.
下列数组定义及赋值,正确的是:
A.byte[]arr=newbyte[15];
B.bytearr=newbyte[20];
C.bytearr[]={1,2,3,4,5};
D.byte[10]arr=newbyte[];
AC解析:
19.
publicstaticvoidmain(String[]args){《插入代码》if(isRight){System.out.println("
right!
"
}}请在《插入代码》处,填入变量isRight声明的同时,进行初始化的代码:
A.booleanisRight=false;
B.intisRight=1;
C.intisRight=0;
D.booleanisRight=true;
AD解析:
20.
下列选项的数据类型中,能存储汉字“达”的是:
A.int
B.byte
C.short
D.char